- Home /
 
camera not been save
Hi, i create a script for a first person controller, basically what i want to do is click to move and hold click to look around, but everytime i hold mouse and move the camera it resets x axis to 0 (y its working fine).
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.AI;
public class NewBehaviourScript : MonoBehaviour { public int tapTimes; public float flt_Timer; public bool IsHoldingDown; public float speedH = 2.0f; public float speedV = 2.0f; private float yaw; private float pitch;
  NavMeshAgent agent;
 
               /IEnumerator ResetTapTimes(){ yield return new WaitForSeconds(resetTimer); tapTimes = 0; }/ private void Timer(){ if (flt_Timer >=0){ flt_Timer -= Time.deltaTime; } } void Start(){
 agent = GetComponent<NavMeshAgent>();
 
               } private void Update(){ Timer();
if (Input.GetMouseButtonUp(0)){if(flt_Timer<=0.1f){
         RaycastHit hit;
         Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
         if(Physics.Raycast(ray, out hit, 100))
         {
             
             agent.SetDestination(hit.point);
             
         }
     }
 
               }
 if  (Input.GetMouseButton(0)){
     
     
    
   yaw += speedH * Input.GetAxis("Mouse Y");
 pitch -= speedV * Input.GetAxis("Mouse X");
 transform.eulerAngles =new Vector3 (yaw,pitch);
 if (flt_Timer<=0.4f){flt_Timer += Time.deltaTime*2;
 }
 }
 
 
 
               } }
Your answer