so i found a cool script on youtube that makes a good looking 3rd person camera script. the script is js, but i am trying to teach myself C# so i translated it with the help of the scripting reference but i ran into a few problems.
my script:
using UnityEngine;
using System.Collections;
public class camFollow : MonoBehaviour {
public LayerMask mask;
public Transform target;
public float height;
public float distance;
public float x;
public float y;
public float yMin;
public float yMax;
void Update () {
x += 3 * Input.GetAxis ("Mouse X");
y += 3 * Input.GetAxis ("Mouse Y");
if(y > yMax){
y = yMax;
}
if(y <yMin){
y = yMin;
}
Quaternion rotation = Quaternion.Euler (y,x, 0);
Vector3 pos = rotation * new Vector3(0, height, -distance) + target.position;
transform.rotation = rotation;
transform.position = pos;
RaycastHit hit;
if(Physics.Linecast(target.position, transform.position, out hit, mask)){
float temDistance = Vector3.Distance(target.position, hit.point);
pos = rotation * Vector3(0, height, -tempDistance) + target.position;
transform.position = pos;
}
}
}
with this i got this error:
Assets/camFollow.cs(34,43): error CS0119: Expression denotes a type', where a
variable’, value' or
method group’ was expected
i got this error before and i found a solution on the internet, so i used the same method to fix it and i changed line 34 to:
pos = rotation * new Vector3(0, height, -tempDistance) + target.position;
but then i got these errors:
Assets/camFollow.cs(34,66): error CS0103: The name `tempDistance’ does not exist in the current context
Assets/camFollow.cs(34,80): error CS1502: The best overloaded method match for `UnityEngine.Vector3.Vector3(float, float, float)’ has some invalid arguments
Assets/camFollow.cs(34,80): error CS1503: Argument #3' cannot convert
object’ expression to type `float’
any idea what i did wrong?