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;
↧