void Start() { Enemy = GetComponentInParent<EnemyGuard>(); PlayerMovement.Instance.RewindEnd += () => { target = null; }; }
// Use this for initialization void Start() { guard = GetComponent<EnemyGuard>(); recordedEvents = new Stack<Position>(); isRewinding = false; PlayerMovement.Instance.RewindBegin += () => { isRewinding = true; guard.preRewind(); }; PlayerMovement.Instance.RewindEnd += () => { isRewinding = false; guard.postRewind(); }; }
// Update is called once per frame void Update() { FOVControl(); if (base.state != Enemy.enemyState.inactive) { int seeState = 0; foreach (FOV fov in fovs) { seeState = fov.canSeePlayer(); if (seeState != 0) { break; } } if (seeState != 0) { Debug.Log("cam: player spotted!"); if (!alertSent) { EnemyGuard[] enemies = GameObject.FindObjectsOfType<EnemyGuard>(); foreach (EnemyGuard enemy in enemies) { if (nearestEnemy == null) { nearestEnemy = enemy; } else if (Vector3.Distance(transform.position, enemy.transform.position) < Vector3.Distance(transform.position, nearestEnemy.transform.position)) { nearestEnemy = enemy; } } if (nearestEnemy != null) { nearestEnemy.investigate = true; nearestEnemy.investigatePos = player.transform.position; } alertSent = true; } } else { if (alertSent) alertSent = false; if(nearestEnemy != null && !nearestEnemy.investigate) { foreach (FOV fov in fovs) { fov.alert = FOV.alertState.normal; } nearestEnemy = null; } } switch (base.state) { case Enemy.enemyState.idle: idle(); break; case Enemy.enemyState.playTurn: playTurn(); break; default: break; } } }