De'Shaun De'Shaun - 7 months ago 29
C# Question

How would i let the c# script know of a collision?

I have this script for this game I'm making and I'm trying to make the object that a bullet hits dissapear.. Heres my script:

void onCollisionEnter()
if (collision.gameObject.tag == "Enemy")

The error says

Severity Code Description Project File Line Suppression State
Error CS0103 The name 'collision' does not exist in the current context First person game.CSharp C:\Users\desha\Documents\First person game\Assets\Prefabs\Bullet_kill.cs 20 Active

It says this error twice, So if collision doesn't exist in this context, How do i get whatever the bullet collides with to disappear?

Please help.


It seems to me you are missing the function input. change this line

void onCollisionEnter()

for this one here:

void OnCollisionEnter(Collision collision)

I hope I was of help. :)

The error appears twice because you are calling "collision" on the if statement, and then again on Destroy(collision.gameobject), which by the way should be Destroy(collision.gameObject).