- Home /
hit coin collider
I have some problem here. I have a coin and a horse. I want my horse when it gets the coin, score will be set. I've try to use raycast hit. but it still didn't work. Can you guys help me please. Here's my code.
Thank you
public class DuaRatusPoint : MonoBehaviour {
PlayerManager player;
GameObject coin;
Ray ray;
RaycastHit hit;
float range = 0.1f;
void Update () {
player = PlayerManager.thisPlayerManager;
//player = GameObject.FindWithTag ("Player");
if (Physics.Raycast (ray, out hit, range)) {
if (player.collider.gameObject.tag == "Coin") {
ScoreScript.addScore (200);
Destroy (gameObject);
}
}
}
First of all, it appears that you're using Physics.Raycast
wrong. Here's the Script Reference page:
http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html
Secondly, is there a particular reason that you're trying to use raycasting ins$$anonymous$$d of a proximity-based solution? Sorry if this is unhelpful but you might explain how you want to the horse to "get" the coin a little more.
Answer by Jamie_h88 · May 18, 2014 at 10:10 AM
This should work unless there was a reason you had to use raycast
PlayerManager player; GameObject coin;
// collision should give you what you are looking for
function OnCollisionEnter(coll: Collision) {
player = PlayerManager.thisPlayerManager;
//player = GameObject.FindWithTag ("Player");
if (coll.gameObject.tag == "Coin") {
ScoreScript.addScore (200);
Destroy (gameObject);
}
}
Your answer
Follow this Question
Related Questions
Click&Drag Misterious Disappearing! 1 Answer
I don't know why i can't detect by ray sth. tagged, 1 Answer
how to get info on what raycast hitted 1 Answer
Need Help with RayCast. No Vector? 1 Answer
Hit collider problem 1 Answer