Hello guys,
I have ran headlong into another problem in my quest to get a basic FPS thingy working. This time it’s getting the cross-hair to change colour.
I should mention that I do have a function that will change the cross-hair colour if I select it using a public var in the Inspector, or, even if I set it by shooting a specific object with an OnCollisionEvent. The problem stems from trying to get the cross-hair graphic to change using a RayCast and/or C#.
The code is I am using is from an older book like this it’s all I know, there is probably a better way - in fact , I’m sure there has to be:
Declaring the Var:
internal var cChange: GameObject;
In Start:
cCHange=GameObject.Find("CursorHolder");
//there is a script there residing there called HideCursor.js
//and a function there called cursorColourChange
Used In function somewhere:
cChange.SendMessage("cursorColourChange",true);
The above in JavaScript works “after” shooting an object: But when I plugged these into the RayCast script it doesn’t.
Declaring:
internal GameObject cChange; //?? is this correct
In Start:
cChange = GameObject.Find ("cursorHolder");
In Function:
cChange.SendMessage("cursorColourChange",true);
And when the raycast hits the specific object, nothing occurs. So I need to know firstly if these should work in the C# script particularly the declaration, or, is there something different going on with the RayCast Script.
Code except:
if (Physics.Raycast (this.transform.position, this.transform.forward, out hit, RayLength)){
//test to see if hitting an object with ray
//without pressing fire will work - it does
if (hit.transform.tag == "enemy") {
print ("I touched: enemy");
//Destroy (hit.transform.gameObject);
cChange.SendMessage ("cursorColourChange", true);
}
......
To anyone who can help here is a “huge” thankyou in advance.
Regards,
CK.