- Home /
Cannot convert 'UnityEngine.GameObject' to 'UnityEngine.Transform'
Hi. I'm working on a voxel project, and to place blocks I have this code:
#pragma strict
var DirtPrefab : Transform;
var placePointTransform : Transform;
function Start () {
placePointTransform = GameObject.Find("PlacePoint");
}
function Update() {
var Block : Transform = Instantiate( DirtPrefab, placePointTransform.position,
Quaternion.identity ); }
I have a prefab called Dirt, and I have an object called PlacePoint, located exactly like a crosshair in front of the player. This is the great script of alucadj, but if you can't fix it, just sent me a minecraft project at micaelunity22@gmail.com
Answer by programmrzinc · Mar 08, 2013 at 11:44 PM
What is happening is that you are getting a gameobject(with GameObject.Find) and you want to are passing it as a transform. Instead of this:
function Start () {
placePointTransform = GameObject.Find("PlacePoint");
}
Replace it with this. \
function Start () {
placePointTransform = GameObject.Find("PlacePoint").transform;
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613094046im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Ball in Pong dissapears after hitting paddle 0 Answers
How to lock the Z axis so my Enemy just flips on the Y axis 1 Answer
Why doesn't my script work? 1 Answer
Rest postion after animation plays 0 Answers