NullReferenceException: Object reference not set to an instance of an object
LookAtTarget.Fire () (at Assets/Scripts/LookAtTarget.cs:26)
using System;
using UnityEngine;
public class LookAtTarget : MonoBehaviour
{
public Rigidbody2D projectile;
public float speed = 1000;
public Transform target;
void Start()
{
InvokeRepeating("Fire", 3, 0.5f);
}
void Update()
{
if(target != null)
{
transform.LookAt(target);
}
}
void Fire()
{
Rigidbody2D instantiatedProjectile = Instantiate(projectile,transform.position,transform.rotation)as Rigidbody2D;
instantiatedProjectile.velocity = new Vector2(instantiatedProjectile.velocity.x,3);
}
}