enemy bullet doesnt move
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!
Your answer
Follow this Question
Related Questions
Score counter not working properly. 1 Answer
How to kill enemy when the bullet hits the BoxColllider2D? 1 Answer
The bullet never destroyed!!! 2 Answers
Trigger is not detecting tag 2 Answers