iam learning a fps game, where i have two scripts 1.mouselookupscript for camera and 2.playermovementscript.
i want to access a variable currentyrotation from the mouselookupscript,but i get an error message regarding the declaration of the script. below are the scripts.
this is a tutorial which is in javascript, but am trying to do it in c#. need help.
MouseLookUpscript
using UnityEngine;
using System.Collections;
public class mouse_lookupScript : MonoBehaviour {
float lookSensitivity = 2f;
float xRotation;
float yRotation;
float currentXrotation;
float currentYrotation;
float xRotationv;
float yRotationv;
float lookSmoothDamp = 0.03f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
xRotation += Input.GetAxis("Mouse Y") * lookSensitivity;
yRotation += Input.GetAxis("Mouse X") * lookSensitivity;
xRotation = Mathf.Clamp(xRotation, -90, 90);
currentXrotation = Mathf.SmoothDamp(currentXrotation, xRotation, ref xRotationv, lookSmoothDamp);
currentYrotation = Mathf.SmoothDamp(currentYrotation, yRotation, ref yRotationv, lookSmoothDamp);
transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
}
}
PlayerMovementscript
using UnityEngine;
using System.Collections;
public class player_movement : MonoBehaviour {
public float walkAccleration = 10f;
public GameObject cameraObject;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.rotation = Quaternion.Euler(0, cameraObject.GetComponent<mouse_lookupScript>().currentYrotation, 0);
}
}
the last line transform.rotation is where i get error. i couldn’t able to access the currentYrotation variable. need help.