- Home /
Question by
Dylanpolis · Aug 02, 2017 at 09:45 PM ·
scripting problemscripting beginnerscriptingbasicsscript error
Trying to setbool of animator from another object c#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Die : MonoBehaviour
{
public GameObject _gameObject;
void Update ()
{
}
void OnTriggerEnter (Collider col)
{
if (col.gameObject.tag == "Weapon")
{
_gameObject.GetComponent<Animator>.SetBool ("isDead", true);
_gameObject.GetComponent<Chase>().enabled = false;
}
}
}
Comment
Best Answer
Answer by Reynarz · Aug 02, 2017 at 09:50 PM
You don't told us what is your problem, but as i can see, there is a sintax problem.
_gameObject.GetComponent<Animator>.SetBool("isDead", true); //Wrong.
_gameObject.GetComponent<Animator>().SetBool("isDead", true); //Sintax ok.
But why?
GetComponent is a generic method!
GetComponent<AndTheType>();
You can say this:
var animator = GetComponent<Animator>();
animator.SetBool("isDead", true);