OK you call it a prefab - did you instantiate the flame bullet? whateverr line 35 is in your flamethrower that is the code that has a problem, and its telling you something is not set or created…
It’s set, so the problem is: The flameThrower works as it supposed. But i want it to unactive until i call Activate(). The first line - setActive(false) - works as i want. But i get the Null Exception when using Activate().
Well there is no “flame” in your heirachy, so, what exactly are you thinking is set? you assigned a prefab to the field perhaps, its clearly not working as its supposed to or you wouldnt be here
So, You need to share that code and enough of it for us to follow what you’re doing…
You need to remember a prefab is a recipie almost it is not something in your scene
The gameObject creates a bullet (the prefab u talking about)
Bullet prefab code:
public class Bullet : MonoBehaviour
{
public GameObject hitEffect;
public float animationTime;
public float damage;
public float timerToDestroy;
private Vector3 scaleHolder;
private void FixedUpdate()
{
timerToDestroy -= Time.deltaTime;
if (timerToDestroy < 0 )
{
Destroy(gameObject);
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.TryGetComponent<Enemy>(out Enemy enemyComponent))
{
enemyComponent.TakeDamage(damage);
//Debug.Log("Bullet deals dmg");
}
GameObject effect = Instantiate(hitEffect, transform.position, Quaternion.identity);
Destroy(effect, animationTime);
Destroy(gameObject);
}
public void GetBiggerProjectile()
{
Vector3 scale = new Vector3(1f, 1f, 0f);
gameObject.transform.localScale += scale;
}
public void SetToDefault ()
{
gameObject.transform.localScale = scaleHolder;
}
public void GetDefault()
{
scaleHolder = gameObject.transform.localScale;
}
}
But the problem not in there: I try to activate the gameObject via Activate() but there’s NullEcxeption. However, the gameObject is a reference to a gameobject is attached to. Thus, i can’t understand how