Quantcast
Channel: Questions in topic: "temporary"
Viewing all articles
Browse latest Browse all 97

Tramsform.position Consider storing temp variable C# problem

$
0
0
I'm having problems trying to figure out what's wrong with what I have. It says "'UnityEngine.Transform.position'. Consider storing the value in a temporary variable" and I tried doing just that and setting it to my thisTransform.position.x and y but still no luck. using UnityEngine; using System.Collections; public class cameraSmoothFollow2D : MonoBehaviour { public GameObject cameraTarget; public GameObject player; public float smoothTime = 0.1f; public bool cameraFollowX = true; public bool cameraFollowY = true; public bool cameraFollowHeight = false; public float cameraHeight = 2.5f; public Vector2 velocity; private Transform thisTransform; void Start () { thisTransform = transform; } void Update () { if(cameraFollowX) { thisTransform.position.x = Mathf.SmoothDamp(thisTransform.position.x, cameraTarget.transform.position.x, ref velocity.x, smoothTime); } if(cameraFollowY) { thisTransform.position.y = Mathf.SmoothDamp(thisTransform.position.y, cameraTarget.transform.position.y, ref velocity.y, smoothTime); } if(!cameraFollowY && cameraFollowHeight) { camera.transform.position.y = cameraHeight; } } } So to wrap this all up I get this error message for the following lines:"error CS1612: Cannot modify a value type return value of `UnityEngine.Transform.position'. Consider storing the value in a temporary variable" 1. thisTransform.position.x = Mathf.SmoothDamp(thisTransform.position.x, cameraTarget.transform.position.x, ref velocity.x, smoothTime); 2. thisTransform.position.y = Mathf.SmoothDamp(thisTransform.position.y, cameraTarget.transform.position.y, ref velocity.y, smoothTime); 3. camera.transform.position.y = cameraHeight;

Viewing all articles
Browse latest Browse all 97

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>