UnAssignedReferenceException…
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class enemy : MonoBehaviour
{
[SerializeField] int Health = 100;
[SerializeField] float shotCounter;
[SerializeField] float minTimeBetweenShots = 0.2f;
[SerializeField] float maxTimeBetweenShots = 1f;
[SerializeField] GameObject Projectile;
[SerializeField] float ProjectileSpeed = 10f;
// Start is called before the first frame update
void Start()
{
shotCounter = Random.Range(minTimeBetweenShots, maxTimeBetweenShots);
}
// Update is called once per frame
void Update()
{
CountDownAndShoot();
}
private void CountDownAndShoot()
{
shotCounter -= Time.deltaTime;
if (shotCounter <= 0f)
{
Fire();
shotCounter = Random.Range(minTimeBetweenShots, maxTimeBetweenShots);
}
}
private void Fire()
{
GameObject laser = Instantiate(Projectile, transform.position, Quaternion.identity) as GameObject; the error pointed this.....
laser.GetComponent<Rigidbody2D>().velocity = new Vector2(0, -ProjectileSpeed);
}
private void OnTriggerEnter2D(Collider2D other)
{
DamageDealer damageDealer = other.gameObject.GetComponent<DamageDealer>();
Health -= damageDealer.GetDamage();
if (Health <= 0)
{
Destroy(gameObject);
}
}
}
In laser defender…
red laser has:
DamageDealer.cs
RigidBody
And Capsule Collider
The enemy has:
Enemy.cs
and Box collider
the error said 9999999999999999+:
The variable Projectile Has not been assigned
need assign projectile of enemy in the inspector.
I ASSIGNED THE PROJECTILE INTHE INSPECTOR
pls help me…