- Home /
              This question was 
             closed Dec 10, 2018 at 08:56 PM by 
             JaykieX for the following reason: 
             
 
            Question is off-topic or not relevant
 
               Question by 
               JaykieX · Dec 10, 2018 at 07:49 PM · 
                c#unity 5uiinstantiateerror message  
              
 
              Instantiate problem with selected objects
Hey, guys, I want to player choose specific locations in the game and by clicking button spawn buildings but I have 2 problems one is when I start to Instantiate next location I click also instantiate and second choosing location reference not set an instance of an object here's the 2 scripts
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class OnClick : MonoBehaviour {
 
 
     [SerializeField]
     public GameObject panel;
 
     public static GameObject CurrentlySelectedGameObject = null;
        
     void Update() /*selecting an object */{
         if (Input.GetMouseButtonDown(0))
         {
             RaycastHit hit;
             Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             if (Physics.Raycast(ray, out hit))
             {
                 if (hit.transform.tag == "EmptyGround")
                 {                       
                     if (panel != null)
                     {
                         panel.SetActive(true);
                     }    
                     CurrentlySelectedGameObject = hit.collider.gameObject;                                             
                 }
             }          
         }    
         if (Input.GetMouseButtonDown(1))
         {
             if (panel != null)
             {
                 panel.SetActive(false);                 
             }
             CurrentlySelectedGameObject = null;               
         }    
     }   
 }
 
^ this one for selecting object and set active building panel
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class BuildManager : MonoBehaviour {
 
 
     [SerializeField]
     private GameObject TownBuilding;
 
     private GameObject BuildingLocation;
 
     [SerializeField]
     private OnClick OnClickScript;
  
     void Update() {
 
         if (OnClick.CurrentlySelectedGameObject != null)
             BuildingLocation.transform.position = OnClick.CurrentlySelectedGameObject.transform.position;    
     }
     
     public void TownBuildingButton()
     {
         if (OnClick.CurrentlySelectedGameObject != null)
         {
             BuildingLocation = Instantiate(TownBuilding);
             Destroy(OnClick.CurrentlySelectedGameObject);               
         }           
     }
 }
 
^ this one for choosing building from panel and spawn in selected location
               Comment
              
 
               
              Follow this Question
Related Questions
UIButton highlighted color not working 0 Answers
How to handle inactive object updates 0 Answers
Instantiated object not showing in scene or hierarchy 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                