This code is calling a function when it collides with ‘Enemy’
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class bullet : MonoBehaviour
{
public float speed = 20f;
public Rigidbody2D rb;
// Start is called before the first frame update
void Start()
{
rb.velocity = transform.up * speed;
}
private void OnTriggerEnter2D(Collider2D hitInfo)
{
Enemy badGuy = hitInfo.GetComponent<Enemy>();
if(badGuy != null)
{
badGuy.die();
}
Destroy(gameObject);
}
}
Line 21 is the error (Assets\bullet.cs(21,20): error CS1061: ) and it’s being crazy over the “.die” part
it says there is no definition " ‘Enemy’ does not contain a definition for ‘die’ and no accessible extension method ‘die’ accepting a first argument of type ‘Enemy’ could be found (are you missing a using directive or an assembly reference?)"
Here is my other code where the method is.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy : MonoBehaviour
{
public void die()
{
Destroy(gameObject);
}
}
Help please. I can’t find the problem.