I don’t know why this script doesn’t work. Am I just misunderstanding something simple. This is the error I get: NullReferenceException: Object reference not set to an instance of an object. This is my script:
using UnityEngine;
using System.Collections;
public class ForceCalculator : MonoBehaviour {
public float angle = 0;
public GameObject Player;
// Use this for initialization
void Start () {
Player = GameObject.Find ("player");
}
// Update is called once per frame
void Update () {
}
public void OnCollisionEnter(Collision col){
if(col.gameObject.name == "Weapon"){
Player.GetComponent<PowerBar>().Force = (Player.GetComponent<PowerBar>().OriginalRotation - transform.Find("player").eulerAngles.y) * Player.GetComponent<PowerBar>().thePower;
Player.rigidbody.AddForce(-transform.Find("player").forward * Player.GetComponent<PowerBar>().Force);
}
}
}
Please don’t link me to script reference. I’ve read it and it hasn’t helped. Please help. I have updated the script with improvements you’ve given me so far. But I still get the same error.