- Home /
can someone tell me what is wrong with my build?
I'm not sure what it is saying in these two lines, can someone please help it's apparently game breaking but it shows no errors before i build it or in any of the scripts
here is the script
using UnityEngine;
using System.Collections;
public class MoveBobbyPin : MonoBehaviour
{
#region Editor Variables
public LockPickManager LockPickManager = null;
public bool EnableInput = false;
public bool EnableUpInput = true;
public bool EnableDownInput = true;
public bool EnableLeftInput = true;
public bool EnableRightInput = true;
public float PinMovementSpeed = 1.0f;
public float VertPinSpeedMultiplier = 1.0f;
public float HorizontalPinSpeedMultiplier = 1.0f;
public AudioClip PinContactSound = null;
public AudioClip LockPickContactSound = null;
private Vector3 OriginalPosition = Vector3.zero;
#endregion
#region Public Methods
public void Start()
{
OriginalPosition = transform.position;
}
public void Update()
{
if(Input.GetKeyDown(KeyCode.E) && LockPickManager.LockPickCompleted == true)
{
ResetBobbyPinPosition();
}
else if(Input.GetKeyDown(KeyCode.E) && LockPickManager.LockPickCompleted == false)
{
ResetBobbyPinPosition();
}
CheckToSeeIfGameHasStarted ();
if(EnableInput == true)
{
if(Input.GetKey("up") && EnableUpInput == true)
{
transform.Translate(Vector3.up * (PinMovementSpeed * VertPinSpeedMultiplier) * Time.deltaTime);
}
if(Input.GetKey("down") && EnableDownInput == true)
{
transform.Translate(Vector3.down * (PinMovementSpeed * VertPinSpeedMultiplier) * Time.deltaTime);
}
if(Input.GetKey("left") && EnableLeftInput == true)
{
transform.Translate(Vector3.left * (PinMovementSpeed * HorizontalPinSpeedMultiplier) * Time.deltaTime);
}
if(Input.GetKey("right") && EnableRightInput == true)
{
transform.Translate(Vector3.right * (PinMovementSpeed * HorizontalPinSpeedMultiplier) * Time.deltaTime);
}
}
}
public void OnCollisionEnter(Collision collidingObject)
{
if(collidingObject.gameObject.tag == "KeySection" && PinContactSound != null)
{
audio.Stop();
audio.clip = PinContactSound;
audio.loop = false;
audio.Play();
}
}
#endregion
#region Private Methods
private void ResetBobbyPinPosition()
{
transform.position = OriginalPosition;
}
private void CheckToSeeIfGameHasStarted()
{
if(LockPickManager.LockPickGameActive == true && LockPickManager != null)
{
EnableInput = true;
}
else if(LockPickManager.LockPickGameActive == false && LockPickManager != null)
{
EnableInput = false;
}
}
#endregion
}
Answer by Clet_ · Apr 29, 2014 at 04:25 AM
You should always check for a null variable before attempting to check for its member variables. The two lines should look like this instead
if(LockPickManager != null && LockPickManager.LockPickGameActive == true)
{
EnableInput = true;
}
else if(LockPickManager != null && LockPickManager.LockPickGameActive == false)
{
EnableInput = false;
}
It's the exact same problem as the above one. You try to access LockPick$$anonymous$$anager's variables without first checking if it is null.
$$anonymous$$ake sure you have an instance of the LockPick$$anonymous$$anager in your scene, because right now, LockPick$$anonymous$$anager is null, thus the NullReferenceException thrown at you
so i fixed that much but what is happening is that the pin that is supposed to move is not moving and i don't know why. The game starts the lock picking game initiates but it won't respond to controls, and i don't know why. it's very frustrating... and on top of that it worked on someone else computer just fine.
i figured out what was wrong there was a duplicate script that didn't get deleted that was causing issues.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
framework not found FBLPromises after build in XCODE...ERROR 1 Answer
I have a build problem android. 0 Answers
i get an error when the host shots the client in Unet 0 Answers
My final project is broken while the project inside the engine is completely normal, HELP! 0 Answers