- Home /
Question by
ObviouslyInsane · Oct 19, 2011 at 12:27 AM ·
colliderontriggerenteroncollisionenter
Little problem with OnTriggerEnter
Hi guys, I have this script here:
enum pickupType {Ammo, Health};
var PickupType : pickupType;
function Update () {
}
function OnTriggerEnter(other : Collider) {
if(other.collider.name == "Player" && pickupType == "Ammo") {
GameObject.FindGameObjectWithTag("Player").GetComponent("WeaponScript").clips += 1;
Debug.Log("Ammo Applied!");
Destroy(gameObject);
}
}
It is attached to game object and its collider is set to trigger. However whenever I walk over it nothing happens. I have tried using other.collider.name/tag/CompareTag and none seem to work. Does anyone see what I might be doing wrong?
Comment
Best Answer
Answer by DaveA · Oct 19, 2011 at 12:28 AM
(Edit)
You should use small letters to start variables and Caps for Classes and Enums and Such.
enum PickupType {Ammo, Health};
var pickupType : PickupType;
pickupType == PickupType.Ammo (no quotes)
Also you can use collider.gameObject to avoid doing the Find
Thanks but now I am getting an error saying $$anonymous$$ identifier: 'Ammo'
Your answer
Follow this Question
Related Questions
Access other collider without use of Trigger collider. 1 Answer
Keep doing something while colliding 1 Answer
2 objects collide, need to destroy one 2 Answers
How to detect collisions in C# 2 Answers