The problem is i need to access an animation script from another script how do i do that???
Please help i dont think there is any need to show an example as it is a simple question well i think it is!
The problem is i need to access an animation script from another script how do i do that???
Please help i dont think there is any need to show an example as it is a simple question well i think it is!
I use C#, but usually what I do is:
1) Add a public variable to the script that wants to access the other script. So for example, if I have a script called "Death" and I want to access "MyAnimationScript", which is attached to some game object that is already instantiated in the editor, i can do:
public class Death : MonoBehavior {
public MyAnimationScript someScript;
void Start () {
}
void Update () {
}
}
2) If my death script is attached to some game object in the editor, that game object will have a slot called "someScript" and I can drag the game object with my animation script on top of it.
Alternatively, you can search for the other script using GameObject.FindGameObjectWithTag and GetComponent. So, if my Animation script was on a game object that had a tag called "PlayerAnimation", I could do:
public class Death : MonoBehavior
{
private MyAnimationScript someScript;
void Start ()
{
someScript = GameObject.FindGameObjectWithTag("PlayerAnimation").GetComponent<MyAnimationScript>();
}
void Update () {
}
}
Now I can access that script and all of it's variables in my Death script by using
someScript.whatever
ScriptThatYouWant = GameObject.Find("[GameObjectName to which target script is attached]").GetComponent<[Name of target script]>();
I am not completely sure what you are trying to achive, but:
//When using static variables you can access them from other scripts
//Call this script TEST.
static var yourVariable = 10;
//This is a new script
function Update ()
{
(script name) TEST.yourVariable(the variable) += 10 * Time.deltaTime;
}
Sorted it thanks guys just added an ontriggerenter to the animation script
My personal best way is:
Write the following line of code(outside start or update or any methods)
public static currentscriptname instant
and in the start function of the same script, write:
instant = this;
If you want to access the script in any other script, write:
/*scriptyouwanttoaccess*/.instant./*whatever you want to do*/