- Home /
Animate object C when object A and B collides.
The title says it all. I want to make a script which will "animation.Play("animationA", PlayMode.StopAll)" for object C when object A and object B collides, but my C# knowledge is not wide enough to do that.Any ideas?
Answer by LSPressWorks · Aug 14, 2017 at 05:22 PM
You need to have object c either found, or assign it with a gameobject variable, then assign it in the inspector. You also need to import the class of the script that calls the animated.
public myClass otherScript;
gameObject thing_B;
gameObject thing_C;
Start()
{
otherScript = Thing_C.getComponent<myClass>();
}
OnCollisionEnter(blahBlah)
{
if(hitter == thing_B)
{
otherScript.CallPublicAnimationSetter();
}
}
So, the steps are
Identify the other objects Import or otherwise declare the Class of the script with the animation, as a variable in the current script. Place a call in OnCollisionEnter to check and see if the other object is object B If it is, then go ahead and call the animate function for thing C.
// SCOPE -> NAME OF THE CLASS -> NAME OF VARIABLE INSTANCE
Public myScriptClass myClassName
Now you can find that via the
otherScript = Thing_C.getComponent<myClass>();
Once that is done, you can call that script from inside the on collision.
Your answer
Follow this Question
Related Questions
Using two animations at once 1 Answer
3D Animations 0 Answers
Animation transition incorrectly rotates player 360 degrees? 0 Answers