- Home /
Question by
Sam2022moon · Apr 29 at 06:48 PM ·
unity 2d
cannt. trigger animation
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Explosion : MonoBehaviour
{
Animator anim;
// Start is called before the first frame update
void awake()
{
anim = GetComponent <Animator>();
}
private void OnEnable()
{
Invoke("OnDisable", 2f);
}
private void OnDisable()
{
gameObject.SetActive(false);
}
// Update is called once per frame
public void StartExplosion(string target)
{
Debug.Log("startExplosion");
anim.SetTrigger("OnExplosion");
Debug.Log("startExplosion2");
switch (target)
{
case "doge":
transform.localScale = Vector3.one * 1.2f;
break;
case "dogelonmas":
transform.localScale = Vector3.one;
break;
case "RocketA":
transform.localScale = Vector3.one;
break;
case "RocketB":
transform.localScale = Vector3.one;
break;
case "samo":
transform.localScale = Vector3.one;
break;
case "shiba":
transform.localScale = Vector3.one;
break;
case "jindoge":
transform.localScale = Vector3.one;
break;
}
Debug.Log("startExplosion3");
}
}
hey guys, I am dying from the frustration now, itd be super grateful if anybody can help.
so i am getting the error "NullReferenceException : Object reference not set to an instance of an object" when it tries to execute anim.SetTrigger in my StartExplosion()
it is extremly frustrating to still get that error, as you can see i put a trigger "OnExplosion" for the condition of the explosion,and there is never a type and set up everythung correctly I believe.
스크린샷-2022-04-30-오전-120035.png
(52.9 kB)
Comment