- Home /
Unable To Pause Animations
Hello, I am currently using this script:
private var enter : boolean;
var target : GameObject;
function Update ()
{
if(enter)
{
target.Animator.speed = 0;
}
}
function OnTriggerEnter (other : Collider)
{
if (other.gameObject.tag == "Player")
{
enter = true;
}
}
And I am receiving this error:
NullReferenceException: Object reference not set to an instance of an object
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.SetProperty (System.Object target, System.String name, System.Object value)
Now I have never tried to pause an animator before and I am using unity 5, would I need to call something along the lines of: "target.getComponent..speed = 0;"?
Ive tried other various ways now, such as just using: Animator.enable and Animator.active, with all the same results. I know I am using the script on an object that has an animator attached, what could be the issue?
I have not used Animator much but does Animator.StartPlayback
resume from Animator.StopPlayback
?
But also, maybe try changing the line target.Animator.speed = 0;
to this.Animator.speed = 0;
Answer by sacajawhoohoo · Aug 02, 2015 at 07:24 PM
I figured it out, I was not using GetComponent first... Its times like this when I feel dumb, well here is the code for anyone who sees fit to need it:
private var enter : boolean;
var target : GameObject;
function Update ()
{
if(enter)
{
target.GetComponent(Animator).enabled = false;
}
}
function OnTriggerEnter (other : Collider)
{
if (other.gameObject.tag == "Player")
{
enter = true;
}
}
Answer by moriggi · Aug 02, 2015 at 06:25 PM
Hello I think to pause the Animator component is not possible. Like other components of GameObject you can make nameOfComponent.enable = false. The Animator component is used to assign animations to a GameObject in your scene. You can create a new state of the controller make a transition in both directions and assign the speed in the inspector to 0 and run this state in the script.You have to change the script, it seems to me that you are using the Boo language!
how would I go about using enabled though? Ive tried multiple times now with the same result: "target.Animator.enabled = false;" "Animator.enabled = false;" and I even have tried the speed method Drumedia said in his comment "target.Animator.speed = 0;" and even "Animator.speed = 0;" I might just be missing something trivial here :/
because theoretically just saying "enabled = false" would work for what im trying to achieve, i just cannot get it to.
gameObject.GetComponent<Animator>().enabled = false;
or
gameObject.GetComponent<Animator>().StopPlayback();
should do it.
I posted my nswer right before yours, that or I did not see yours, you get a thumbs up in any case for your outstanding help.
haha thanks ;) i was 2 $$anonymous$$utes slow! $$anonymous$$y answer is C# lol
Your answer
Follow this Question
Related Questions
Animation doesn't play 1 Answer
Set up Animator with specific seconds 1 Answer
Animation in android game not working 2 Answers
What is the difference between 'Animator' & 'Animation'? 1 Answer