- Home /
C# transform position
transform.position.x =Mathf.Clamp(transform.position.x, minPosX, maxPosX);
transform.position.z =Mathf.Clamp(transform.position.z, minPosZ, maxPosZ);
Hi, I have these lines in my code and here's an error:
error CS1612: Cannot modify a value type return value of `UnityEngine.Transform.position'. Consider storing the value in a temporary variable
This script is for panning on Android. Someone said that it's impossible to modify single parameter in C# and you need to convert it into some temporary variable, but I don't know what to do with "Mathf.Clamp" and the whole line. Help please
Answer by robertbu · Apr 23, 2014 at 06:58 PM
This is what they are suggesting by using a temporary variable:
Vector3 pos = transform.position;
pos.x =Mathf.Clamp(pos.x, minPosX, maxPosX);
pos.z =Mathf.Clamp(pos.z, minPosZ, maxPosZ);
transform.position = pos;
Yes, that or transform.pos = new Vector3(0f,transform.pos.y+12,0f)
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
An NPC "moonwalks" 2 Answers
Distribute terrain in zones 3 Answers
The name `DebugUtils' does not exist in the current context 1 Answer