-
Notifications
You must be signed in to change notification settings - Fork 0
/
laser.cs
52 lines (45 loc) · 1.04 KB
/
laser.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
using UnityEngine;
using System.Collections;
public class laser : MonoBehaviour {
LineRenderer line;
void Start ()
{
line = gameObject.GetComponent<LineRenderer>();
line.enabled = false;
}
void Update ()
{
if(GameObject.Find ("FPSController").GetComponent<playerMovement>().firegun)
{
Debug.Log ("SHOOT!");
StopCoroutine("FireLaser");
StartCoroutine("FireLaser");
}
}
IEnumerator FireLaser()
{
line.enabled = true;
while(Input.GetButton("Fire1"))
{
Ray ray = new Ray(transform.position, new Vector3(1,0,0));
RaycastHit hit;
line.SetPosition(0, ray.origin);
if(Physics.Raycast(ray, out hit, 100))
{
Debug.Log("HITITTT!");
line.SetPosition(1, hit.point);
if(hit.rigidbody.tag== "Enemy")
{
Destroy(hit.transform.gameObject);
Debug.Log("HITITTT!2");
hit.rigidbody.AddForceAtPosition(transform.forward* 5, hit.point);
}
}
else
Debug.Log("NO it!");
line.SetPosition(1, ray.GetPoint(100));
yield return null;
}
line.enabled = false;
}
}