Help Changing Texture On Instantiated Object.

Updated on January 9, 2017 in [A] Unity Scripting
Share on Facebook0Tweet about this on Twitter0Share on Google+0Share on Reddit0
1 on January 9, 2017

Hello. I Am Trying To Make A “Building” Type Game, And I Am Trying To Instantiate Objects With Different Textures. I Made This Script, Which Works Fine In All Other Ways, But Doesn’t Change Texture Of Instantiated Object.

//Variables For Material Stuff
@Header ("Material Stuff")
var Materials : Texture[];
var Material_Selected : int;
//Variables For Model Stuff
@Header ("Model Stuff")
var Models : GameObject[];
var Model_Selected : int;
//Variables For Checking Stuff
@Header ("Checking Stuff")
var Player : Transform;
var Distance_Y : int = -45;
var Distance_X : int = -45;
var Space_Taken : boolean;
//___________________________________________________________//
function Update () {
//For Placement
if(Input.GetKey("space") && Space_Taken == false){var Clone1 = Instantiate(Models[Model_Selected], transform.position, transform.rotation); Clone1.GetComponent.().material.mainTexture = Materials[Material_Selected];}
//For Movement
if(Input.GetKeyDown("w") && Distance_Y < 45){transform.Translate (0,1,0); Distance_Y += 1; }
if(Input.GetKeyDown("s") && Distance_Y > -45){transform.Translate (0,-1,0); Distance_Y -= 1;}
if(Input.GetKeyDown("d") && Distance_X < 45){transform.Translate (1,0,0); Distance_X += 1;}
if(Input.GetKeyDown("a") && Distance_X > -45){transform.Translate (-1,0,0); Distance_X -= 1;}
if(Input.GetKey("up")){Player.Translate(Vector3.up * .3);}
if(Input.GetKey("down")){Player.Translate(Vector3.down * .3);}
if(Input.GetKey("right")){Player.Translate(Vector3.right * 0.3);}
if(Input.GetKey("left")){Player.Translate(Vector3.left * 0.3);}
}
//For Checking If Space Is Taken
function OnTriggerStay(info : Collider){if(info.tag == "Block"){Space_Taken = true;}}
function OnTriggerExit(info : Collider){Space_Taken = false;}
//___________________________________________________________//

Thanks Ahead Of Time, SkelloWare.

  • Liked by
Reply
0 on January 9, 2017

I Restarted Unity And It Is Working Now.

  • Liked by
Reply
Cancel