public void StartLabeling() { OVRInput.Controller controller = grabbedBy == Hand.Right ? OVRInput.Controller.RTouch : OVRInput.Controller.LTouch; OVRInput.SetControllerVibration(1, 1, controller); Destroy(LaserInstance); Vector3 rot = transform.rotation.eulerAngles; rot = new Vector3(rot.x - 90, rot.y, rot.z); LaserInstance = Instantiate(LaserStyle, postItsParent.transform.position, Quaternion.Euler(rot)); LaserInstance.transform.parent = transform; LaserScript = LaserInstance.GetComponent <Hovl_Laser>(); LaserScript2 = LaserInstance.GetComponent <Hovl_Laser2>(); audio.Play(); }
void Update() { //Enable lazer if (Input.GetMouseButtonDown(0)) { Destroy(Instance); Instance = Instantiate(Prefabs[Prefab], FirePoint.transform.position, FirePoint.transform.rotation); Instance.transform.parent = transform; LaserScript = Instance.GetComponent <Hovl_Laser>(); LaserScript2 = Instance.GetComponent <Hovl_Laser2>(); } //Disable lazer prefab if (Input.GetMouseButtonUp(0)) { if (LaserScript) { LaserScript.DisablePrepare(); } if (LaserScript2) { LaserScript2.DisablePrepare(); } Destroy(Instance, 1); } //To change lazers if ((Input.GetKey(KeyCode.A) || Input.GetAxis("Horizontal") < 0) && buttonSaver >= 0.4f)// left button { buttonSaver = 0f; Counter(-1); } if ((Input.GetKey(KeyCode.D) || Input.GetAxis("Horizontal") > 0) && buttonSaver >= 0.4f)// right button { buttonSaver = 0f; Counter(+1); } buttonSaver += Time.deltaTime; //Current fire point if (Cam != null) { RaycastHit hit; //DELATE THIS IF YOU WANT TO USE LASERS IN 2D var mousePos = Input.mousePosition; RayMouse = Cam.ScreenPointToRay(mousePos); //ADD THIS IF YOU WANT TO USE LASERS IN 2D: RaycastHit2D hit = Physics2D.Raycast(RayMouse.origin, RayMouse.direction, MaxLength); if (Physics.Raycast(RayMouse.origin, RayMouse.direction, out hit, MaxLength)) //CHANGE THIS IF YOU WANT TO USE LASERRS IN 2D: if (hit.collider != null) { RotateToMouseDirection(gameObject, hit.point); //LaserEndPoint = hit.point; } else { var pos = RayMouse.GetPoint(MaxLength); RotateToMouseDirection(gameObject, pos); //LaserEndPoint = pos; } } else { Debug.Log("No camera"); } }