i need help with my scripts
Hi, I am fairly new to unity and I am trying to make my first game but I got stuck with those errors which I don't know how to fix. If you guys know how to fix those errors please tell me.
NullReferenceException: Object reference not set to an instance of an object
FollowPlayer.Update () (at Assets/Scripts/FollowPlayer.cs:17)
NullReferenceException: Object reference not set to an instance of an object
PlayerMovement.FixedUpdate () (at Assets/Scripts/PlayerMovement.cs:24)
My FollowPlayer Script is
using UnityEngine;
public class FollowPlayer : MonoBehaviour
{ public Transform player;
public Vector3 offset;
public TriggerCamera triggercamera;
void Start()
{triggercamera = GetComponent();
}
// Update is called once per frame
void Update()
{ if (triggercamera.AnimationIsGoing == false)
{if (GameObject.FindWithTag("Player"))
{transform.position = player.position + offset;
}
else
{Debug.Log("An animation is going");
return;
}
}
}
}
My PLayerMovement Script is:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{ public Rigidbody rb;
public float forwardForce = 2000f;
public float sidewaysForce = 500f;
public TriggerCamera triggercamera;
// Start is called before the first frame update
void Start()
{triggercamera = GetComponent();
}
// Update is called once per frame
void FixedUpdate()
{ if (triggercamera.AnimationIsGoing == false)
{ rb.AddForce(0, 0, forwardForce * Time.deltaTime);
if (Input.GetKey("d"))
{ rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
if (Input.GetKey("a"))
{rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
if (rb.position.y < -2f)
{FindObjectOfType().EndGame();
}
}
}
}
And my TriggerCamera script is:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TriggerCamera : MonoBehaviour
{public bool AnimationIsGoing = true;
void OnTriggerEnter(Collider other)
{ AnimationIsGoing = false
}
}