Raycast problem (7665)

Hello guys

I was wondering if some one could help me? i am making a game in unity and i cant get something to work, basically what i want to do is if my play walks next to an object i want it to show my 3d text. i have made the 3d text invisible when the game starts i have placed a cube which has a raycast on it. when i go next to the box the 3d text should appear up can any one help me plz... here is the script that i have come up with

function update (){

gameObject.active = false;

}

function update (){ var hit : RaycastHit;

if (Physics.Raycast (transform.position, transform.forward, hit,6 )){ if (hit.collider.gameObject.tag == "Box and text " ){ (gameObject.tag == "Press X"); gameObject.active = true ;

} }}

this first line basically makes the 3d text on the box disappear as soon as the game is loaded then the next part is where the Raycast comes in. its basically saying if i am 6 mitres next to the cube show the 3d text please can you help. also the scrip is attached to the 3d text i have also tried to connect the script to the cube but same thing happens if i am in the right distance the 3d text does not appear

You can never "use" an EXE directly. It's most likely an installer which will extract the actual DLL(s) you need somewhere. You have to copy those DLLs into your assets folder in order to use the connector.

2 Answers

2

You might want to put the line:

gameObject.active = false;

In Awake() or Start(). (Or, just make the object initially inactive using the inspector.) As is, if you activate the object, it'll just immediately become inactive again.

I'm not completely clear as to what objects those scripts are attached to, but I take it the first 'update' function is associated with the text object, and the second is associated with the player. In any case, keep in mind that the line:

gameObject.active = true;

References the game object to which the script in question is attached. If the objective is to make the text object active, you may need to store a reference to the text object in the player script, and activate the object via the reference.

thank you so much helped me so much :)

You'll want to put the gameObject.active = false; in a Start() function like...

function Start() { gameObject.active = false; }

that'll fix ur problem

thank you very much this and the other solutions have helped thank you