- Home /
 
               Question by 
               BigDakaFa7 · Jun 22, 2013 at 04:20 PM · 
                guierrorgameobjectraycasttransform  
              
 
              I am getting an error and cant figure out why, Help please?
Ok the error is on line 39 and it is Error CS0039: Cannot convert type 'UnityEngine.Transform' to 'UnityEngine.GameObject' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion (CS0039) (Assembly-CSharp)
 using UnityEngine;
 using System.Collections;
 [RequireComponent(typeof(MeshCollider))]
 public class HUD : MonoBehaviour {
     private Ray ray;
     private RaycastHit hit;
     public Texture box;
     private bool showGUI;
     private string selectedObject = "";
     public Transform ballPrefab;
     public Transform cubePrefab;
     private Vector3 screenPoint;
     private Vector3 offset;
     private bool menuShow = false;
     // Use this for initialization
     void Start () {
         
     }
     
     // Update is called once per frame
     void Update () {
     buildMode();
     }
     
     void buildMode()
     {
     
         if(selectedObject != "")
         {
             if(selectedObject == "Cube")
             {
                 if(Input.GetMouseButtonDown(0))
                 {
                     Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                     RaycastHit hit;
                     if(Physics.Raycast(ray, out hit, 100))
                     {
                         Transform newTransform = Instantiate(ballPrefab, hit.point, Quaternion.identity) as Transform;
                         GameObject newGameObject = newTransform as GameObject;
                         newGameObject.name = "Ball";
                     }
                 }
             }
         }
     }
     void OnGUI()
     {
         if(GUI.Button(new Rect(0,190,100,50),"Menu"))
         {
             
             menuShow = true;
             Debug.Log("pressed");
             
         }
         
         if(menuShow)
         {
             GUI.Box(new Rect(100,190,500,50),"");
             if(GUI.Button(new Rect(100,190,50,50), box))
             {
                 menuShow = false;
                 selectedObject = "Cube";
             }
         }
         
     }
     
  
 }
               Comment
              
 
               
              Answer by Chomprel · Jul 09, 2013 at 04:51 PM
Try using: GameObject newGameObject.gameObject.
The transform is a transform, not a GameObject! But it can reference it's own gameObject directly. (You dont actually need to use a variable, you can always access it by using newTransform.gameObject)
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                