- Home /
cannot implicitly convert type unityengine.vector3' to unityengine.transform'
public TextMesh PartAmountTextMesh;
public void AddBodyPart()
{
Transform newPart;
if (firstPart){
newPart = (Instantiate (BodyPrefab, new Vector3(0, 0, 0), Quaternion.identity) as GameObject).transform;
//Error in this Line Bellow
PartAmountTextMesh.transform.parent = newPart.position + new Vector3(0, 0.5f, 0); //Error here
firstPart = false;
}
else
{
newPart = (Instantiate(BodyPrefab, BodyParts[BodyParts.Count - 1].position, BodyParts[BodyParts.Count - 1].rotation) as GameObject).transform;
newPart.SetParent(transform);
BodyParts.Add(newPart);
}
}
can you please edit the question so it can be read more easily?
Answer by Matt1000 · Nov 15, 2018 at 01:49 PM
Its simple acutally. You are setting a transfor, not its positon. Among other things, the transform controls position, scale and rotation. So, if you want to assign a new position to a certain transform you should do it like this:
PartAmountTextMesh.transform.parent.position = newPart.position + new Vector3(0, 0.5f, 0);
And that's it. Hope it helps ; )
EDIT:
As @Bunny83 pointed out, perhaps you didn't want to access the parent but just set the position and the predictor changed it. if that's the case just change parent for position and you're good to go.
I would assume he wanted to write:
PartAmountText$$anonymous$$esh.transform.position
ins$$anonymous$$d of
PartAmountText$$anonymous$$esh.transform.parent
but code autocomplete has picked "parent" ins$$anonymous$$d of "position". Anyways you are correct about the error.
Your answer
Follow this Question
Related Questions
Get Random Number for each player from Dice 1 Answer
No overload for method 'AddForce' takes 3 arguments 1 Answer
Why does my character only rotate once when it stops moving? 0 Answers
InvokeRepeating time doesn't sync within the same update function 2 Answers
csc.exe has stopped working ,csc.exe has stoped working 0 Answers