okay so, i’m preparing my finals and i’ve come across this one thing that wont work i dont know how to fix.
the thing is i have made a prefab for the bullet, i have added the collider and when i was working on the two scripts (one for the boss and one for the bullet itself) i found that it was creating the bullet, then destroying then creating it again, but with no movement, it stayed inside the boss the whole time.
here are the two scripts, the first one is for the boss, and the other for the bullet:
public Transform pj; //this is the character you can move and stuff
public int hp;
public GameObject prefabBala;
void Start()
{
InvokeRepeating("shoot", 0.1f, 3);
}
void shoot()
{
if (pj.transform.position.y >= 40)
{
GameObject bullet = Object.Instantiate (prefabBala);
bullet.transform.position = transform.position;
bullet.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
}
}
void OnTriggerEnter2D(Collider2D info)
{
if (info.gameObject.CompareTag("balapj"))
{
hp = hp - 1;
if (hp == 0)
{
Destroy(this.gameObject);
SceneManager.LoadScene("victoria");
}
}
}
public float velocidad; //this is the speed
void Start()
{
Destroy(this.gameObject, 1);
}
void update()
{
transform.position -= transform.up * velocidad * Time.deltaTime;
}
void OnTriggerEnter2D(Collider2D info)
{
if (info.gameObject.CompareTag("personaje"))
{
Destroy(this.gameObject);
}
}
sorry about the spanish, and thanks to everyone who has read this far!