- Home /
Question by
rapinnz · Jan 02, 2018 at 08:37 PM ·
scripting problemscript errorscriptingproblemscripterror
Cant play animation ontriggerenter plz help C#
this is what i got plz help if you can im working on a project for a school's up comming event that needs to be done by march 2018. thanks to those who can help.
using UnityEngine;
using System.Collections;
public class Keyandlock : MonoBehaviour
{
public Animation anim;
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Key")
{
//Debug.Log ("Detected");
transform.GetComponent<Animation>();
}
}
}
Comment
Best Answer
Answer by leSamo · Jan 02, 2018 at 08:50 PM
This line:
transform.GetComponent<Animation>();
just gets the component and does nothing with it. You probably wanted to do:
transform.GetComponent<Animation>().Play();
Your answer
Follow this Question
Related Questions
Making a character jump and crouch using a Joystick 1 Answer
Activate/Deactivate Scripts form another Script 2 Answers
Visual Studio Code Intellisense 0 Answers
error CS1525: Unexpected symbol 'rigidbody' 1 Answer
Why won't my scripts work? 1 Answer