SebastianLawe

Untitled

Feb 24th, 2015
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.60 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Sucubus : MonoBehaviour {
  5.     public PlayerController _target;
  6.     public GameObject trap;
  7.     public float speed;
  8.     bool beenSeen = false;
  9.     public SucubusState currentState;
  10.     // Use this for initialization
  11.     void Start() {
  12.         currentState = SucubusState.NotSeen;
  13.     }
  14.     public enum SucubusState {
  15.         NotSeen = 0,
  16.         FollowTrap = 2,
  17.         TemptPlayer = 3
  18.     }
  19.     // Update is called once per frame
  20.     void Update() {
  21.         if (_target != null) {
  22.             float distance = Vector2.Distance(_target.transform.position, transform.position);
  23.             switch (currentState) {
  24.                 case SucubusState.NotSeen:
  25.                     if (_target != null) {
  26.                         transform.LookAt(_target.transform, transform.up);
  27.                         rigidbody.AddRelativeForce(0, 0, speed, ForceMode.VelocityChange);
  28.                     }
  29.                     break;
  30.                 case SucubusState.FollowTrap:
  31.                     transform.LookAt(trap.transform, transform.up);
  32.                     rigidbody.AddRelativeForce(0, 0, speed, ForceMode.VelocityChange);
  33.                     break;
  34.                 case SucubusState.TemptPlayer:
  35.                     rigidbody.AddRelativeForce(0, 0, 0, ForceMode.VelocityChange);
  36.                     transform.LookAt(_target.transform, transform.up);
  37.                     break;
  38.             }
  39.             if (currentState != SucubusState.NotSeen) {
  40.                 currentState = distance < 2 ? SucubusState.FollowTrap : SucubusState.TemptPlayer;
  41.             }
  42.         }
  43.     }
  44.  
  45.     void OnTriggerEnter(Collider collider) {
  46.         PlayerController target = collider.GetComponent<PlayerController>();
  47.         if (target != null) {
  48.             if (_target == null) {
  49.                 _target = target;
  50.             }
  51.         }
  52.     }
  53.     void OnBecameVisible() {
  54.         if (!beenSeen) {
  55.             currentState = SucubusState.FollowTrap;
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment