- Home /
NullReferenceException: Object reference not set to an instance of an object Line 19
My problem: I don't quite understand why my script won't work becuase I am relatively new to unity3d.
What my script is supposed to do: My script is supposed to be a script for my lava, the last object collided with that has the tag "Ground" becomes the new public variable gameobject "bawb" and if the player collides with the a gameobjet with the tag "lava" it will change the player's position to that of the current bawb variable + 1 Vector y value
what my script actualy does: the aforementioned error is what happens and the script does nothing
my lava script
using UnityEngine;
using System.Collections;
public class LavaScript : MonoBehaviour {
public GameObject Player;
public Health Health1;
public GameObject bawb;
// Update is called once per frame
void OnCollisionEnter(Collider other)
{
if (other.CompareTag("Ground"))
{
bawb = (other.gameObject);
}
if (other.CompareTag("Lava"))
{
Health1.ChangeHealth();
Player.transform.position = bawb.transform.position + new Vector3(0, 1, 0);
}
}
}
the health script function my lava script is refrencing
private void CheckHealth()
{
Hp--;
}
Answer by dragonking300 · Jan 03, 2017 at 03:24 AM
edited my code a little and now here is the new code, still not solved tho ;(
using UnityEngine;
using System.Collections;
public class LavaScript : MonoBehaviour {
public GameObject Player;
public Health Health1;
public GameObject bawb;
// Update is called once per frame
void OnCollisionEnter(Collision other)
{
if (other.collider.CompareTag("Ground"))
{
bawb = (other.gameObject);
}
if (other.collider.CompareTag("Lava"))
{
Health1.ChangeHealth();
Player.transform.position = bawb.transform.position + new Vector3(0, 1, 0);
}
}
}
Did you manually assign Health1 in the editor? Does it have public ChangeHealth() method?
Your answer
Follow this Question
Related Questions
instantiating unique classes of a type 0 Answers
I need some help with my high score.,I need help with my highsore. 1 Answer
Multiple Cars not working 1 Answer
"Only assignment, call, increment, decrement and new object expressions can be used as statements" 1 Answer
How do you check if a game object is set active using an if statement? 2 Answers