using System.Collections; using System.Collections.Generic; using UnityEngine; public class TankShoot : MonoBehaviour { [Header("Tank")] public float speed = 10.0f; public float rotationSpeed = 100.0f; [Header("Bullet")] public GameObject bullet; public Transform bulletPos; public float bulletSpeed = 1000f; //- public float bulletTime = 10f; void Update() { float translation = Input.GetAxis("Vertical") * speed * Time.deltaTime; float rotation = Input.GetAxis("Horizontal") * rotationSpeed * Time.deltaTime; transform.Translate(0f, 0f, translation); // -translation transform.Rotate(0f, rotation, 0f); if (Input.GetButtonDown("Fire1")) { GameObject bull = Instantiate(bullet, bulletPos.position, transform.rotation); bull.GetComponent().AddForce(-transform.forward * bulletSpeed); Destroy(bull, bulletTime); } } }