- Home /
Playing animation for object if hit by player camera s ray
Where is problem in my code?
function Update () {
var hit : RaycastHit;
var fwd = transform.TransformDirection (Vector3.forward);
if (Physics.Raycast (transform.position, fwd, 2)) {
if(hit.collider.gameObject.tag == "GameController") {
print("Jabadabaduuuuuu");
//Play animation
}
}
}
BTW how can i create new tag? When i click add tag, it creates new layer
Thank you ツ
Answer by ExplodingCookie · Jul 01, 2013 at 08:41 PM
You need that tag for your script to work. You set up tags by clicking the arrow on the top left side of the tag manager window. the code you use to play the animation is
hit.collider.animation.Play(animationName)
insert this snippet under your play animation comment
~ExplodingCookie
But im getting the
NullReferenceException: Object reference not set to an instance of an object Doors.Update () (at Assets/Doors.js:14)
error again
The Raycast check you are using does not have a reference to the hit data container replace this line
if (Physics.Raycast (transform.position, fwd, 2)) {
with this
if (Physics.Raycast (transform.position, fwd, hit, 2)) {
this should fix your issue. :)
~ExplodingCookie
Your answer
Follow this Question
Related Questions
Raycast only works right next(practically on top of) object 0 Answers
Scripting Help 1 Answer
GUI Button vs RayCasting as input for random animation. 0 Answers
animation problem 1 Answer
How to make char animation idle 0 Answers