Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Sucubus : MonoBehaviour {
- public PlayerController _target;
- public GameObject trap;
- public float speed;
- bool beenSeen = false;
- public SucubusState currentState;
- // Use this for initialization
- void Start() {
- currentState = SucubusState.NotSeen;
- }
- public enum SucubusState {
- NotSeen = 0,
- FollowTrap = 2,
- TemptPlayer = 3
- }
- // Update is called once per frame
- void Update() {
- if (_target != null) {
- float distance = Vector2.Distance(_target.transform.position, transform.position);
- switch (currentState) {
- case SucubusState.NotSeen:
- if (_target != null) {
- transform.LookAt(_target.transform, transform.up);
- rigidbody.AddRelativeForce(0, 0, speed, ForceMode.VelocityChange);
- }
- break;
- case SucubusState.FollowTrap:
- transform.LookAt(trap.transform, transform.up);
- rigidbody.AddRelativeForce(0, 0, speed, ForceMode.VelocityChange);
- break;
- case SucubusState.TemptPlayer:
- rigidbody.AddRelativeForce(0, 0, 0, ForceMode.VelocityChange);
- transform.LookAt(_target.transform, transform.up);
- break;
- }
- if (currentState != SucubusState.NotSeen) {
- currentState = distance < 2 ? SucubusState.FollowTrap : SucubusState.TemptPlayer;
- }
- }
- }
- void OnTriggerEnter(Collider collider) {
- PlayerController target = collider.GetComponent<PlayerController>();
- if (target != null) {
- if (_target == null) {
- _target = target;
- }
- }
- }
- void OnBecameVisible() {
- if (!beenSeen) {
- currentState = SucubusState.FollowTrap;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment