-
Notifications
You must be signed in to change notification settings - Fork 0
/
spear.cs
54 lines (49 loc) · 1.53 KB
/
spear.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class spear : MonoBehaviour
{
public Vector3[] newVertices;
public int[] newTriangles;
private Mesh mesh;
public MeshCollider meshCol;
public List<Vector3> vertices;
public GameObject player;
public bool addforce = true;
public Transform top;
// Start is called before the first frame update
void Start()
{
Destroy(gameObject, 3f);
player = GameObject.FindGameObjectWithTag("Player");
meshCol = GetComponent<MeshCollider>();
mesh = new Mesh();
GetComponent<MeshFilter>().mesh = mesh;
mesh.Clear();
mesh.vertices = newVertices;
mesh.triangles = newTriangles;
mesh.RecalculateNormals();
meshCol.sharedMesh = mesh;
}
// Update is called once per frame
void Update()
{
if (newVertices[4].z < 2)
{
newVertices[4].z += .05f;
newVertices[5].z -= .05f;
}
else if(addforce)
{
transform.LookAt(player.transform.position);
transform.eulerAngles = new Vector3(0, transform.rotation.eulerAngles.y, 0);
addforce = false;
GetComponent<Rigidbody>().useGravity = true;
Vector3 a = player.transform.position + Vector3.up - transform.position;
//a.y = 0;
GetComponent<Rigidbody>().AddForce(a*200);
}
mesh.vertices = newVertices;
mesh.RecalculateNormals();
}
}