void HandleRusherAI() { Character.Input input = new Character.Input(Quaternion.identity, Vector3.zero, false, false, false, false, false); if (!_target) { Character[] charactersInScene = FindObjectsOfType <Character>(); foreach (Character otherCharacter in charactersInScene) { if (otherCharacter != GetComponent <Character>()) { if (otherCharacter.Team != GetComponent <Character>().Team) { _target = otherCharacter; } } } } else { input.targetRotation = Quaternion.LookRotation(_target.transform.position - transform.position); input.moveDirection = transform.forward; } GetComponent <Character>().input = input; }
void Update() { Character.Input input = new Character.Input(Quaternion.identity, Vector3.zero, false, false, false, false, false); // Get shooting/aim input if (Input.GetMouseButton(0)) { input.shoot = true; } if (Input.GetMouseButton(1)) { input.aim = true; } // Get movement input if (Input.GetKey(KeyCode.W)) { input.moveDirection += Vector3.forward; } else if (Input.GetKey(KeyCode.S)) { input.moveDirection += Vector3.back; } if (Input.GetKey(KeyCode.A)) { input.moveDirection += Vector3.left; } else if (Input.GetKey(KeyCode.D)) { input.moveDirection += Vector3.right; } // Get throwing weapon input input.throwWeapon = Input.GetKeyDown(KeyCode.G); input.use = Input.GetKeyDown(KeyCode.E); input.reload = Input.GetKeyDown(KeyCode.R); // Calculate aim target Vector3 aimTarget = UnityEngine.Input.mousePosition; aimTarget.z = Mathf.Abs(Camera.main.transform.position.y - transform.position.y); aimTarget = Camera.main.ScreenToWorldPoint(aimTarget); aimTarget = new Vector3(aimTarget.x, 1, aimTarget.z); input.targetRotation = Quaternion.LookRotation(aimTarget - transform.position); _targetCharacter.input = input; }