Advertisement
CassataGames

Untitled

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