I’ve been looking into this a bit and still havn’t got it to work. I’d be willing to either get them working together somehow, or use a shared global variable, or rewrite the csharp script to js (although it extends another csharp script i didnt write). I moved the csharp script to Standard Assets which seemed to help, but I still get an error: NullReferenceException: Object reference not set to an instance of an object
BallControl.Update () (at Assets/Game/BallControl.js:37)
I’m using the following cSharp script to make a GUI for my game:
using UnityEngine;
using System.Collections;
public class GameGui : VRGUI
{
public int lives = 5;
public int score = 0;
public override void OnVRGUI()
{
GUI.skin.label.fontSize = 30;
GUILayout.BeginArea(new Rect(300, 100, 200, 100));
GUILayout.Label("Lives: " + lives);
GUILayout.EndArea();
GUILayout.BeginArea(new Rect(900, 100, 200, 100));
GUILayout.Label("Score: " + score);
GUILayout.EndArea();
}
public void RemoveLife() {
lives = lives - 1;
}
}
This is the JS script i am trying to change the cSharp one from:
#pragma strict
var left = -100;
var right = 100;
var top = 100;
var bottom = -100;
var xV : float;
var yV : float;
var zV : float;
var damage = 100;
var guiscript : GameGui;
function Start () {
xV = Random.Range(0,0.5);
yV = Random.Range(0,0.5);
zV = Random.Range(0,2.0);
}
function Update () {
//move the ball
transform.position.x = transform.position.x + xV;
transform.position.y = transform.position.y + yV;
transform.position.z = transform.position.z + zV;
//ball bounces
if(transform.position.x < left || transform.position.x > right) xV = -1 * xV;
if(transform.position.y < left || transform.position.y > right) yV = -1 * yV;
if(transform.position.z > right) zV = -1 * zV;
//lose a life
if(transform.position.z < left) {
transform.position = Vector3(0,0,0);
xV = Random.Range(0,0.5);
yV = Random.Range(0,0.5);
zV = Random.Range(0,2.0);
guiscript = this.GetComponent("GameGui");
guiscript.RemoveLife();
}
}
I am just trying to change the GUI in csharp when stuff happens in js. Any help would be much appreciated!