Chest creating
I made a art for a chest, one is open and another is closed, and i want to make a script when player collide with chest and press E or open button to destroy that chest that is closed and create a chest that is open.
I made a script only for destroying because i dunno what should i use to create a new object .
Here is script :
 if (kovcegtxt) {
             if (Input.GetButtonDown ("Open")) {
    
                 Destroy (kovceg);
 
                 kovcegtxt = false;
 
                 ChestUI.SetActive (false);
             }
There is kovcegtxt just for when collide to show some text.
Chest is "kovceg" in here.
kovceg is defined like this :
 kovceg = GameObject.FindGameObjectWithTag ("Zkovceg");
Can't we do like, We will replace the texture form the Sprite or Image(Unity Ui) ins$$anonymous$$d of destroying & re-create the image.??
if yes then just take the reference of the texture and replace it when you want
Ye that is what i could do , but i'm new to this so what function shall i use , for example my sprite is called openchest.png ?
Answer by Hurag · Jan 19, 2016 at 04:53 AM
Okey i did a code that changes a sprite, but i would like now when it changes sprite to set it on x and y a little up than closed chest because sprite of open chest is a little down because it's bigger. How could i do that? Here is code:
 void ChangeTheDamnSprite ()
     {
         if (spriteRenderer.sprite == sprite1) 
         {
             spriteRenderer.sprite = sprite2;
         }
         else
         {
             spriteRenderer.sprite = sprite1; 
         }
     }
Your answer
 
 
             Follow this Question
Related Questions
How do you access the transform of a gameobject and put it in a variable? 3 Answers
how to move the enemy in the current position of the player but only ones? 0 Answers
Camera isn't move position? Why my camera isn't change position? 0 Answers
Terrain height -> loosing Players GO childs 0 Answers
How to change position of gameobject 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                