View difference between Paste ID: WRULepce and RPDr6fNS
SHOW: | | - or go back to the newest paste.
1
using UnityEngine;
2
using System.Collections;
3
4
public class MovingSpikedFuse : MonoBehaviour {
5
6
    public Direction MovingDirection;
7
    public bool Chasing;
8
9
	void FixedUpdate ()
10
    {
11
        DetectHit(transform.TransformDirection(Vector3.right), Direction.Left); // Left
12
        DetectHit(transform.TransformDirection(Vector3.left), Direction.Right); // Right
13
        DetectHit(transform.TransformDirection(Vector3.up), Direction.Up);      // Top
14
        DetectHit(transform.TransformDirection(Vector3.down), Direction.Down);  // Bottom
15
    }
16
17
    public void DetectHit(Vector3 RayDir, Direction CheckDir)
18
    {
19-
        Ray CurrentRay = new Ray(transform.position, RayDir);
19+
        if (!Chasing)
20-
        RaycastHit hit;
20+
21
            Ray CurrentRay = new Ray(transform.position, RayDir);
22-
        if (Physics.Raycast(CurrentRay, out hit))
22+
            RaycastHit hit;
23
24-
            if (hit.collider.name == "player model")
24+
            if (Physics.Raycast(CurrentRay, out hit))
25
            {
26-
                MovingDirection = CheckDir;
26+
                if (hit.collider.name == "player model")
27-
                Chasing = true;
27+
                {
28
                    MovingDirection = CheckDir;
29
                    Chasing = true;
30
                }
31
            }
32
        }
33
    }
34
35
    public enum Direction { Left, Right, Up, Down };
36
}