Basically, when a button is pressed, if the player is called on to do so, he should either earn points or take damage. This is my first scripting attempt, and even though things seem simple enough, I keep getting a NullReferenceException with this description:
“NullReferenceException: Object reference not set to an instance of an object
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.SetProperty (System.Object target, System.String name, System.Object value)
ButtonScript.ButtonPress (UnityEngine.GameObject target) (at Assets/Scripts/ButtonScript.js:25)
ButtonScript.Update () (at Assets/Scripts/ButtonScript.js:19)”
Here is the script for player input:
var damage:int;
var success:int;
var power:int;
var buttonInput:String;
private var playerCamera:GameObject;
private var anxietyscript;
private var victoryscript;
private var buttonRing:boolean;
function Awake(){
playerCamera=GameObject.Find("PlayerCamera");
healthscript=playerCamera.GetComponent("Health Script");
successscript=playerCamera.GetComponent("Success Script");
buttonRing=false;
}
function Update(){
if (Input.GetButtonDown (buttonInput)){
ButtonPress(gameObject);
}
}
function ButtonPress (target:GameObject){
if (buttonRing==false){
playerCamera.anxietyscript.ApplyDamage=damage;
}
if (buttonRing==true){
playerCamera.victoryscript.ApplySuccess=success;
}
}
This is one script being referenced:
var success:int;
var score:int;
var max:int;
private var successLevel:GameObject;
function Awake(){
successLevel=GameObject.Find("SuccessLevel");
}
function Start(){
score=0;
successLevel.guiText.text=success.ToString();
}
//For now we will use a guiText but will eventually enable the gauge.
function ApplySuccess(score:int){
score+=success;
successLevel.guiText.text=success.ToString();
if (score>=max){
WinPlayer();
}
}
function WinPlayer(){
Application.LoadLevel("Scene-ClosingVictory");
}
And the other:
var health:int;
var damage:int;
private var healthLevel:GameObject;
function Awake(){
healthLevel=GameObject.Find("HealthLevel");
}
function Start(){
health=100;
healthLevel.guiText.text=health.ToString();
}
function Update(){
if (health>200){
health=200;
}
}
//For now we will use a guiText but will eventually enable the gauge.
function ApplyDamage(damage:int){
health-=damage;
healthLevel.guiText.text=health.ToString();
if (health<=0){
KillPlayer();
}
}
function KillPlayer(){
Application.LoadLevel("Scene-ClosingFail");
}
Many thanks in advance for forgiving my amateur scripting and for not being able to find the solution by Googling it (I tried). One solution on here suggested the asker not use variables with names identical to classes, so (I am pretty sure) I didn’t make that mistake. Any ideas?