Hi, i have a script for a projectile that’s going upwards but after i shoot one time i can’t shoot again.
This is the script:
using UnityEngine;
public class BulletMovement : MonoBehaviour
{
public GameObject bullet;
public float speed;
private bool isActive=false;
public float maxY;
public Transform spawnPos;
public GameObject spawnee;
private SpawnerWeapon spawnerWeapon;
// Use this for initialization
void Start()
{
if (isActive == false)
{
if (Input.GetMouseButtonDown(0))
{
isActive = true;
}
}
}
// Update is called once per frame
void Update()
{
if (isActive == false)
{
if (Input.anyKeyDown)
{
isActive = true;
}
}
if (bullet.transform.position.y < maxY && isActive == true)
{
bullet.transform.Translate(new Vector3(0, speed, 0) * Time.deltaTime);
}
if (bullet.transform.position.y >= maxY)
{
Debug.Log("Distrus");
Destroy(gameObject);
isActive = false;
Instantiate(spawnee, spawnPos.position, spawnPos.rotation);
return;
}
}
void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.tag == "Enemy")
{
Debug.Log("Lovit");
Destroy(gameObject);
;
isActive = false;
Instantiate(spawnee, spawnPos.position, spawnPos.rotation);
return;
}
}
}