Reputation: 818
This is the error I am getting:
Assets/Scripts/CameraScript.cs(60,39): error CS1612: Cannot modify a value type return value of `UnityEngine.Transform.position'. Consider storing the value in a temporary variable
This is my code:
void Start (){
thisTransform = transform;
// Disable screen dimming
Screen.sleepTimeout = 0;
}
void Update (){
//Reset playerscore
playerScore = settings.playerScore;
//Smooth follow player character
if (target.position.y > thisTransform.position.y) {
thisTransform.position.y = Mathf.SmoothDamp( thisTransform.position.y,
target.position.y, ref velocity.y, smoothTime);
}
}
Upvotes: 0
Views: 827
Reputation: 3277
Transform.position.y
is read-only in C#, so in order to modify it you'll need to store the value of Transform.position
to a temporary variable first, change the value from that variable, then assign it back to Transform.position
:
Vector3 temp = thisTransform.position;
temp.y = Mathf.SmoothDamp( temp.y, target.position.y, ref velocity.y, smoothTime);
thisTransform.position = temp;
Upvotes: 2
Reputation: 54212
You can't set the thisTransform.position.y
value alone. Set the thisTransform.position
instead.
For example:
if (target.position.y > thisTransform.position.y) {
thisTransform.position = new Vector3(thisTransform.position.x,
Mathf.SmoothDamp( thisTransform.position.y, target.position.y, ref velocity.y, smoothTime),
thisTransform.position.z);
}
Upvotes: 2