Advertisement
CassataGames

Untitled

May 21st, 2012
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.         if (!Chasing)
  20.         {
  21.             Ray CurrentRay = new Ray(transform.position, RayDir);
  22.             RaycastHit hit;
  23.  
  24.             if (Physics.Raycast(CurrentRay, out hit))
  25.             {
  26.                 if (hit.collider.name == "player model")
  27.                 {
  28.                     MovingDirection = CheckDir;
  29.                     Chasing = true;
  30.                 }
  31.             }
  32.         }
  33.     }
  34.  
  35.     public enum Direction { Left, Right, Up, Down };
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement