Take Two:
Hello all,
I am working with the trial and I’m seeing some script weirdness which is a good chance of my misunderstanding, too.
I have a C# Script object which is the heart of my game logic and it keeps track of variables. One is which object is currently being hovered over with the mouse. So I have a GameWorld script attached to an empty “Game” GameObject.
I then have a JS script with OnMouseEnter/Exit functions that call update the GameWorld script that looks like this:
private var engine = null;
function Awake () {
engine = GameObject.Find("Game").GetComponent("GameWorld");
if(engine) {
Debug.Log("Found GameWorld: "+engine.name);
}
else {
Debug.LogWarning("Did NOT find GameWorld");
}
}
function OnMouseEnter() {
engine.StartMouseOver(this);
}
function OnMouseExit () {
engine.EndMouseOver(this);
}
The Engine class looks like this:
using UnityEngine;
public class GameWorld : MonoBehaviour {
static GameWorld singleton;
private GameObject mouse_over = null;
// Use this for initialization
void Start () {
singleton = this;
mouse_over = gameObject;
Debug.Log("GameWorld initialized!");
}
// Update is called once per frame
void Update () {
}
static public void StartMouseOver (GameObject obj)
{
Debug.Log("SetMouseOver: "+obj.name);
}
static public void EndMouseOver (GameObject obj)
{
Debug.Log("EndMouseOver: "+obj.name);
}
static public GameObject MouseOver
{
get
{
return singleton.mouse_over;
}
}
}
I then attached this to a palm tree GameObject in the world.
Here’s the issues:
-
The JS script complains that GameWorld.StartMouseOver and EndMouseOver methods do not exist.
-
I added a call in the JS to “engine.MouseOver” and it reads that property just fine. (I have another component displaying the name of that property so I know it’s seeing the GameWorld class and interacting with it.
If anyone can see anything I’m doing wrong on why the script won’t see those two methods, that would be great!
Thanks for your time and help!
Edited: solved my first issue so edited this post to show what I’m currently having problems with
Edit: Figured this one out, too. I’ll leave it for other noobies like me, though.
1. I realized if I put the GameWorld class under a folder called Plugins, I can refer to it directly. Yay!
2. In the JS script I sent in ‘this’ which is not the GameObject but the Script component. I changed to StartMouseOver(gameObject) and it’s all good!