using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShootingScript : MonoBehaviour
{
public GameObject rocketPrefab;
//from muzzle place
public Transform firePoint;
private void Update()
{
//triggers whenever we press the button
if (Input.GetButtonDown("Fire1"))
{
Debug.Log("Rocket Shot!");
Instantiate(rocketPrefab, firePoint.position, firePoint.rotation);
}
}
}
-------------------- above is my ShootingScript -----------------------------------
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RocketProperty : MonoBehaviour
{
public float rocketSpeed = 20f;
public float destroyTime = 8f;
private void Start()
{
//destroy the object after some time
Destroy(gameObject, destroyTime);
}
private void Update()
{
//move it along the z-axis at a constand speed
transform.Translate(rocketSpeed * Time.deltaTime, 0f, 0f); //x.y.z
}
}
------------------------------Above is my rocket, which is my bullet property Script-----------------------