Hi, Im trying to be able to instantiate different gameObjects by choosing between them using set keys. I have written a script containing the information but it will not instantiate the objects although it will display the information of which object it is meant to instantiate in the corner. Can anybody see a problem with my script?
var wall : GameObject;
var crane : GameObject;
var pallet : GameObject;
var speed = 0;
private var one : boolean;
private var two : boolean;
private var three : boolean;
function Update () {
if(Input.GetKey(KeyCode.E))
{
one = true;
two = false;
three = false;
}
if(Input.GetKey(KeyCode.R))
{
one = false;
two = true;
three = false;
}
if(Input.GetKey(KeyCode.T))
{
one = false;
two = false;
three = true;
}
}
if( Input.GetButtonDown( "Fire2" one ))
{
var instantiatedWall : GameObject = Instantiate(
wall, transform.position, transform.rotation );
instantiatedWall.velocity =
transform.TransformDirection( Vector3( 0, -speed, 0 ) );
Physics.IgnoreCollision( instantiatedWall. collider,
transform.root.collider );
}
if( Input.GetButtonDown( "Fire2" ) two )
{
var instantiatedCrane : GameObject = Instantiate(
crane, transform.position, transform.rotation );
instantiatedCrane.velocity =
transform.TransformDirection( Vector3( 0, -speed, 0 ) );
Physics.IgnoreCollision( instantiatedCrane. collider,
transform.root.collider );
}
if( Input.GetButtonDown( "Fire2" ) three )
{
var instantiatedPallet : GameObject = Instantiate(
pallet, transform.position, transform.rotation );
instantiatedPallet.velocity =
transform.TransformDirection( Vector3( 0, -speed, 0 ) );
Physics.IgnoreCollision( instantiatedCrane. collider,
transform.root.collider );
}
function OnGUI()
{
if(one)
{
GUI.Label (Rect (10, 10, 100, 20), "Wall");
} else if(two)
{
GUI.Label (Rect (10,10,100, 20), "Crane");
}
if(three)
{
GUI.Label (Rect (10, 10, 100, 20), "Pallet");
}
}
Please enclose your script with coding tags, here is a link to show you how. It is very hard to read your scripting in the current form.
Sorry, Thank you for reminding me
var wall : GameObject;
var crane : GameObject;
var pallet : GameObject;
var speed = 0;
private var one : boolean;
private var two : boolean;
private var three : boolean;
function Update () {
if(Input.GetKey(KeyCode.E))
{
one = true;
two = false;
three = false;
}
if(Input.GetKey(KeyCode.R))
{
one = false;
two = true;
three = false;
}
if(Input.GetKey(KeyCode.T))
{
one = false;
two = false;
three = true;
}
if( Input.GetButtonDown( "Fire2" one ))
{
var instantiatedWall : GameObject = Instantiate(wall, transform.position, transform.rotation );
instantiatedWall.velocity = transform.TransformDirection( Vector3( 0, -speed, 0 ) );
Physics.IgnoreCollision( instantiatedWall. collider, transform.root.collider );
}
if( Input.GetButtonDown( "Fire2" ) two )
{
var instantiatedCrane : GameObject = Instantiate(crane, transform.position, transform.rotation );
instantiatedCrane.velocity = transform.TransformDirection( Vector3( 0, -speed, 0 ) );
Physics.IgnoreCollision( instantiatedCrane. collider, transform.root.collider );
}
if( Input.GetButtonDown( "Fire2" ) three )
{
var instantiatedPallet : GameObject = Instantiate(pallet, transform.position, transform.rotation );
instantiatedPallet.velocity = transform.TransformDirection( Vector3( 0, -speed, 0 ) );
Physics.IgnoreCollision( instantiatedCrane. collider, transform.root.collider );
}
}
function OnGUI()
{
if(one)
{
GUI.Label (Rect (10, 10, 100, 20), "Wall");
} else if(two) {
GUI.Label (Rect (10,10,100, 20), "Crane");
}
if(three)
{
GUI.Label (Rect (10, 10, 100, 20), "Pallet");
}
}
That should sort it, you had some brackets wrong
Thank you very much, that solved the problem. You had one or two mistakes yourself but they were tiny problems, here is the working scripts
var wall : GameObject;
var crane : GameObject;
var pallet : GameObject;
var speed = 0;
private var one : boolean;
private var two : boolean;
private var three : boolean;
function Update () {
if(Input.GetKey(KeyCode.E))
{
one = true;
two = false;
three = false;
}
if(Input.GetKey(KeyCode.R))
{
one = false;
two = true;
three = false;
}
if(Input.GetKey(KeyCode.T))
{
one = false;
two = false;
three = true;
}
if( Input.GetButtonDown( "Fire2") one )
{
var instantiatedWall : GameObject = Instantiate(wall, transform.position, transform.rotation );
instantiatedWall.velocity = transform.TransformDirection( Vector3( 0, -speed, 0 ) );
Physics.IgnoreCollision( instantiatedWall. collider, transform.root.collider );
}
if( Input.GetButtonDown( "Fire2" ) two )
{
var instantiatedCrane : GameObject = Instantiate(crane, transform.position, transform.rotation );
instantiatedCrane.velocity = transform.TransformDirection( Vector3( 0, -speed, 0 ) );
Physics.IgnoreCollision( instantiatedCrane. collider, transform.root.collider );
}
if( Input.GetButtonDown( "Fire2" ) three )
{
var instantiatedPallet : GameObject = Instantiate(pallet, transform.position, transform.rotation );
instantiatedPallet.velocity = transform.TransformDirection( Vector3( 0, -speed, 0 ) );
Physics.IgnoreCollision( instantiatedCrane. collider, transform.root.collider );
}
}
function OnGUI()
{
if(one)
{
GUI.Label (Rect (10, 10, 100, 20), "Wall");
} else if(two) {
GUI.Label (Rect (10,10,100, 20), "Crane");
}
else if(three) {
GUI.Label (Rect (10,10,100, 20), "Pallet");
}
}