slomg_
slomg_

Reputation: 45

How do I fix this error on unity: Cannot implicitly convert type float to UnityEngine.transform

I am trying to do something, and I get this error:

Cannot implicitly convert type float to UnityEngine.transform

code:

private Transform EndPos;
EndPos = transform.position.x + 40f;
transform.position = Vector3.MoveTowards(transform.position, EndPos, moveSpeed * Time.deltaTime);

Thank you for your help

Upvotes: 0

Views: 674

Answers (2)

Amir Javed
Amir Javed

Reputation: 19

Instead of doing "EndPos = transform.position.x + 40f;" Change the "X" of EndPos (EndPos.position.x) and then use it.

Upvotes: 0

LLSv2.0
LLSv2.0

Reputation: 543

EndPos is type Transform. You are trying to set it to transform.position.x which is type float.

I think what you are trying to do is:

EndPos.position = transform.position + (Vector3.right * 40f);

This sets EndPos 40 units to the right of transform's current position.

Upvotes: 1

Related Questions