【Unity エラー】CS1612 : Mathf.Clamp
エラー内容
どうも一回要素を取り出してあげなければならないようだ。
Assets/Script/_Script_player2/PlayerManager.cs(20,35): error CS1612: Cannot modify a value type return value of `UnityEngine.Transform.position'. Consider storing the value in a temporary variable
修正前
void Update (){ if(Input.GetKeyDown(KeyCode.Space)){ iTween.PunchScale(gameObject,iTween.Hash("amount", new Vector3(0.1f,0.1f,0),"time",1.7f,"easetype",iTween.EaseType.easeOutCubic)); transform.position.x = Mathf.Clamp(transform.position.x,-10,10); } }
修正後
void Update (){ if(Input.GetKeyDown(KeyCode.Space)){ iTween.PunchScale(gameObject,iTween.Hash("amount", new Vector3(0.1f,0.1f,0),"time",1.7f,"easetype",iTween.EaseType.easeOutCubic)); Vector3 temp = transform.position; temp.x = Mathf.Clamp(temp.x,-10,10); transform.position = temp; } }