I have been trying to get the bullets disappear when they hit the walls. Enemy and bullet both are destroyed when it is a Trigger, but the bullet does not disappear when it is a collision. Look at the following image, c# script and advice.
public class Bullet : MonoBehaviour
{
[SerializeField] float bulletSpeed = 10f;
Rigidbody2D myRigidbody;
PlayerMovement player;
float xSpeed;
void Start()
{
myRigidbody = GetComponent<Rigidbody2D>();
player = FindObjectOfType<PlayerMovement>();
xSpeed = player.transform.localScale.x * bulletSpeed;
}
void Update()
{
myRigidbody.velocity = new Vector2(xSpeed, myRigidbody.velocity.y);
}
void OnCollisonEnter2D(Collision2D other)
{
Destroy(gameObject);
}
void OnTriggerEnter2D(Collider2D other)
{
if(other.tag == "Enemy")
{
Destroy(other.gameObject);
}
Destroy(gameObject);
}
}