private void Update() { //if (Input.GetButtonDown("Jump")) player.Jump(); player.Direction = GetDirection(INPUT.KEYBOARD); if (Input.GetButtonDown("Fire1")) { shooter?.Shoot(ShootDirection()); } }
protected override void ControlPerFrame() { if (Input.GetButton("Fire2")) { Shooter?.ContinuousShoot(); } else { if (Input.GetButtonDown("Fire1")) { Shooter?.Shoot(); } } }
void OnTriggerStay(Collider Object) { // Checking for the player tag is only for no crashing if (isOpponent(Object)) { float speed = 0; if (Object.gameObject.tag == "Npc") { ObjectTransformer d = Object.GetComponent <ObjectTransformer>(); speed = d.TranslationSpeed; } else if (Object.gameObject.tag == "Player") { ShipControl s = Object.GetComponent <ShipControl>(); speed = s.CurrentSpeed; } //Debug.Log(speed); // Check the predicted position given the current flying velocity Vector3 targetPosM = PredictPosition.Predict(Object.transform.position, speed * Object.transform.forward, top.position, shootL.ProjectileSpeed); Vector3 targetPosL = PredictPosition.Predict(Object.transform.position, speed * Object.transform.forward, muzzleLeft.position, shootL.ProjectileSpeed); Vector3 targetPosR = PredictPosition.Predict(Object.transform.position, speed * Object.transform.forward, muzzleRight.position, shootR.ProjectileSpeed); // TODO: Only get random target sometimes targetPosM = GetRandomTarget(targetPosM, 1); //targetPosL = GetRandomTarget(targetPosL, 1); //targetPosR = GetRandomTarget(targetPosR, 1); Vector3 lookPos = targetPosM - top.position; lookPos.y = 0; Quaternion rotation = Quaternion.LookRotation(lookPos); //Quaternion b = Quaternion.Euler(0, this.transform.eulerAngles.y, 0); Vector3 eul = rotation.eulerAngles; eul.y -= this.transform.eulerAngles.y; Quaternion rotation2 = Quaternion.Euler(eul.x, eul.y, eul.z); top.localRotation = Quaternion.Slerp(top.transform.rotation, rotation2, Time.deltaTime * 100); Vector3 objPos = Object.transform.position; float angle = getXrotation(muzzleLeft.position, targetPosL); muzzleLeft.localEulerAngles = new Vector3(angle * Mathf.Rad2Deg, -90, 0); angle = getXrotation(muzzleRight.position, targetPosR); muzzleRight.localEulerAngles = new Vector3(angle * Mathf.Rad2Deg, -90, 0); float diff = (Object.transform.position - top.position).magnitude; // Only shoot in case of in shoot radius if (diff < shootDistance) { shootL.Shoot(); shootR.Shoot(); } } }
public void Shoot() { chracterShooter.Shoot(); }