- Home /
Button then instanitates gameobject
I have two gui buttons at the moment within my weapon window. I have two problems.
- When i click somewhere on the map the gameobject i instantiate goes halfway through the ground. 
- When i click a button then click the other one my gameobject still instantiates even though im clicking buttons. 
code:
// Update is called once per frame void Update() { if (button == true) { onMap = false;
 
                    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
     RaycastHit hit = new RaycastHit();
     if (Physics.Raycast(ray, out hit))
     {
         if (Input.GetMouseButtonDown(0))
         {
             Instantiate(weapons[0], hit.point, Quaternion.identity);
             onMap = true;
         }
         if (onMap == true)
         {
             button = false;
         }
     }
 }
 if (button1 == true)
 {
     onMap = false;
     Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
     RaycastHit hit = new RaycastHit();
     if (Physics.Raycast(ray, out hit))
     {
         if (Input.GetMouseButtonDown(0))
         {
            //if (!onMouseOver)
             //{
                 Instantiate(weapons[1], hit.point, transform.rotation);
                 onMap = true;
            // }
         }
         if (onMap == true)
         {
             button1 = false;
         }
     }
 }
 }
 void OnGUI() { if (displayWeaponCache) { weaponWindowRect = GUI.Window(WEAPON_CACHE_ID, new Rect(Offset, Screen.height - (Offset + weaponWindowHeight), Screen.width - (Offset * 2), weaponWindowHeight), WeaponCacheWindow, "Weapons"); }
  if (GUI.Button(new Rect(575.0f, 5.0f, 25.0f, 25.0f), "X"))
 {
     displayWeaponCache = !displayWeaponCache;
 }
 }
 public void WeaponCacheWindow(int winID) { if (GUI.Button(new Rect((buttonWidth - 10), (buttonHeight - 10), buttonWidth, buttonHeight), "Turret1")) { button = true; button1 = false; onMap = false; } if (GUI.Button(new Rect((buttonWidth + buttonWidth + 5), (buttonHeight - 10), buttonWidth, buttonHeight), new GUIContent(square))) { button1 = true; button = false; onMap = false; } } 
}
Also using code like this how do i make it so i cnt plant gameobjects in the path of the enemy.
Answer by Samir 1 · Mar 06, 2011 at 04:37 PM
i got this to work i while back i will just make it answered :)
Your answer
 
 
             Follow this Question
Related Questions
Bullet Prefab not instantiating 1 Answer
Using GUI and check what button was pressed 1 Answer
Searching for gameobjects with a tag and creating a button for each one? 1 Answer
Problem with texture to reset and re-enter the same texture 0 Answers
Is it possible to link a UI element to a gameobject? 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                