how to resolve nullReferenceExetion error in Unity 3d

Asked

Viewed 23 times

0

I was making a shooting game Nightmare from Unity traningday appeared that mistake

inserir a descrição da imagem aqui

the code is this

using UnityEngine;
using System.Collections;

public class CameraFollow : MonoBehaviour
{
    public Transform target;            // The position that that camera will be following.
    public float smoothing = 5f;        // The speed with which the camera will be following.

    Vector3 offset;                     // The initial offset from the target.

    void Start ()
    {
        // Calculate the initial offset.
        offset = transform.position - target.position;
    }

    void FixedUpdate ()
    {
        // Create a postion the camera is aiming for based on the offset from the target.
        Vector3 targetCamPos = target.position + offset;

        // Smoothly interpolate between the camera's current position and it's target position.
        transform.position = Vector3.Lerp (transform.position, targetCamPos, smoothing * Time.deltaTime);
    }
}
  • Have you tried instantiating the variable? 'public Vector3 offset;'

  • I’m new with c# and I don’t know how to instantiate

  • According to the error message, the problem is occurring on line 27 of the class source file *Enemymovement. Please put the source code of this class also in the question, @Danielcorreasantos, and if possible also highlight to us which is the line 27, why here in Stackoverflow the lines of code are not listed.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.