Hi guys. I'm following a guide to make a 3d shooter, but I'm pretty stuck. I know there are other threads with almost exactly the same issue, but I really don't understand those, so I hope you can help me.
The error:
NullReferenceException: Object reference not set to an instance of an object
Iron_man_movement.Move (Single h, Single v) (at Assets/ironman/Iron_man_movement.cs:33)
Iron_man_movement.FixedUpdate () (at Assets/ironman/Iron_man_movement.cs:25)
The Code:
using UnityEngine;
using System.Collections;
using UnitySampleAssets.CrossPlatformInput;
public class Iron_man_movement : MonoBehaviour {
Vector3 movement;
Rigidbody playerRigidBody;
// Use this for initialization
void Start () {
}
void awake () {
playerRigidBody = GetComponent ();
}
// Update is called once per frame
void Update () {
}
void FixedUpdate() {
float h = CrossPlatformInputManager.GetAxisRaw ("Horizontal");
float v = CrossPlatformInputManager.GetAxisRaw ("Vertical");
Move (h, v);
}
void Move (float h, float v){
movement.Set (h, 0f, v);
movement = movement.normalized * 5.0f;
playerRigidBody.MovePosition(transform.position + movement);
}
}
↧