public void Sonar() { if (Input.GetButtonUp("Fire1")) { Debug.Log("Hit the button"); _wolfie.SetWolfieState(new WanderingState(_wolfie, _steeringCharacter)); } }
public void Navigate() { if (isHunting) { Debug.DrawLine(chicken.pooledObjects[targetNum].transform.position, _steeringCharacter.transform.position, Color.red); _steeringCharacter.transform.position = new Vector3(_steeringCharacter.transform.position.x + Vector3.Normalize(seekDirection).x *Time.deltaTime * 2, 0, _steeringCharacter.transform.position.z + Vector3.Normalize(seekDirection).z *Time.deltaTime * 2); if (Vector3.Distance(chicken.pooledObjects[targetNum].transform.position, _steeringCharacter.transform.position) < 0.2) { chicken.pooledObjects[targetNum].SetActive(false); _wolfie.SetWolfieState(new WanderingState(_wolfie, _steeringCharacter)); } } }
/// <summary> /// O(n) proformance real-time detection /// </summary> public void Sonar() // Global Interfacial Method { ///<example> /// /// Testing (building connection between main character and other game objects) /// /// </example> if (Input.GetButtonDown("Fire1")) { Debug.Log("Hit the button"); _wolfie.SetWolfieState(new EvasionState(_wolfie, _steeringCharacter)); } for (int i = 0; i < temp.pooledAmount; i++) { Debug.DrawLine(temp.pooledObjects[i].transform.position, _steeringCharacter.transform.position, Color.red); //Detect the distance between obstacles and main characters if (temp.pooledObjects[i].activeInHierarchy && Vector3.Distance(temp.pooledObjects[i].transform.position, _steeringCharacter.transform.position) < 1) { //_wolfie.SetWolfieState(new EvasionState(_wolfie, _steeringCharacter)); } } for (int i = 0; i < chicken.pooledAmount; i++) { //Debug.DrawLine(chicken.pooledObjects[i].transform.position, _steeringCharacter.transform.position, Color.red); if (chicken.pooledObjects[i].activeInHierarchy && Vector3.Distance(chicken.pooledObjects[i].transform.position, _steeringCharacter.transform.position) < 5) { _wolfie.SetWolfieState(new SeekingState(_wolfie, _steeringCharacter)); // _steeringCharacter.transform.position = new Vector3(_steeringCharacter.transform.position.x + wanderInheritence._velocity.x * Time.deltaTime, 0, _steeringCharacter.transform.position.z + wanderInheritence._velocity.z * Time.deltaTime); break; } if (chicken.pooledObjects[i] == null) { return; } } }