Hey guys, i’m creating a little 3D Pac-Man like and I would like to add the little yellow collectibles but the script that I did doesn’t work and I don’t know why:
void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.tag == "Player")
{
Destroy(gameObject);
}
}
}
I need help!
I would suggest OnTriggerEnter instead and setting the collider on your pickup to be a trigger. Does your pac man have a rigidbody on it as well?
Thanks for the answer but
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class pickup : MonoBehaviour {
void OnTriggerEnter(Collision collision)
{
if(collision.gameObject.tag == "Player")
{
Destroy(gameObject);
}
}
}
Don’t work either.
Do you have a rigidbody on your player? and are they tagged Player.
Maybe it’s a problem with my FPSController?
There’s a FirstPersonCharacter and a Capsule with it.
Yes rigidbody and the tag is there.
Is your player’s and the collectables collider set to “Is Trigger”?
Try to turn off the “Is Trigger” on the player and turn it on on the collectables.
Thanks downhilldan! Works!