public void Attack() { transform.position = transform.position; pawn.mover.Move(Vector3.zero); transform.LookAt(chaseTarget.transform); if (Time.time > stateStartTime + pawn.shootWait) { GameObject bullet = Instantiate(pawn.bulletPrefab, pawn.bulletSpawn.transform.position, pawn.bulletSpawn.transform.rotation); bulletMover bm = bullet.GetComponent <bulletMover>(); bm.SetPlayer(pawn); } }
// Update is called once per frame void Update() { //Tell the mover that I am not moving Vector3 directionToMove = Vector3.zero; //if the player presses W if (Input.GetKey(KeyCode.UpArrow)) { //tell the move to move in a forward direction directionToMove += Vector3.forward; } //if the player presses S if (Input.GetKey(KeyCode.DownArrow)) { //tell the move to move in a backward direction directionToMove -= Vector3.forward; } //if the player presses A if (Input.GetKey(KeyCode.LeftArrow)) { //tell the mover to rotate in a leftward direction data.mover.Rotate(-data.rotateSpeed * Time.deltaTime); } //if the player presses D if (Input.GetKey(KeyCode.RightArrow)) { //tell the move to rotate in a rightward direction data.mover.Rotate(data.rotateSpeed * Time.deltaTime); } //if the player presses space bar if (Input.GetKeyDown(KeyCode.Keypad0)) { GameObject bullet = Instantiate(data.bulletPrefab, data.bulletSpawn.transform.position, data.bulletSpawn.transform.rotation); bulletMover bm = bullet.GetComponent <bulletMover>(); bm.SetPlayer(data); } data.mover.Move(directionToMove); }
IEnumerator Shoot() { while (true) { if (Input.GetAxis("Fire1") == 1) // Deals with bullet instantiation { GameObject clone = Instantiate(bullet, transform.position, Quaternion.identity); // Instantiates the bullet bulletMover mover = clone.GetComponent <bulletMover>(); // Grabs the bulletMover script mover.input_position = transform.position; // and sets the input_position vector to be the player's vector yield return(new WaitForSecondsRealtime(shotDelay)); } else { yield return(new WaitForFixedUpdate()); } Debug.Log("Loop"); } }