Answer the question
In order to leave comments, you need to log in
Why doesn't SetActive() work in Unity?
Hello, I have a problem: The fact is that on my character there is a Playerattack script, and it looks like this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Playerattack : MonoBehaviour
{
public float attackTime;
public float startTimeAttack;
public GameObject attack;
private void Start()
{
attack.gameObject.SetActive(false);
}
void Update()
{
if(attackTime <= 0)
{
if(Input.GetKeyDown(KeyCode.E))
{
Debug.Log("start time");
attack.gameObject.SetActive(true);
attackTime = startTimeAttack;
}
}
else if(attackTime > 0)
{
attackTime -= Time.deltaTime;
Debug.Log("stop time");
attack.gameObject.SetActive(false);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AttackScript : MonoBehaviour
{
public void OnTriggerStay2D(Collider2D other)
{
if(other.tag == "enemy")
{
Debug.Log("Damage was dealt!");
}
}
}
Answer the question
In order to leave comments, you need to log in
Update is not called on a disabled object. As well as collision, physics and animator
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question