using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Objects : MonoBehaviour
{
public float maxScale = 10.0f;
public float minScale = 2.0f;
public float shrinkSpeed = 1.0f;
public float rotatingSpeed = 3f;
public bool automaticScale = false;
public bool rotateOnMouseMove = false;
public bool rotateOnMouseDrag = true;
private float targetScale;
private Vector3 v3Scale;
void Start()
{
v3Scale = transform.localScale;
}
void Update()
{
RaycastHit hit;
Ray ray;
if (Input.GetMouseButton(1))
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit) && hit.transform == transform)
{
targetScale = minScale;
v3Scale = new Vector3(targetScale, targetScale, targetScale);
}
if (automaticScale == false)
transform.localScale = Vector3.Lerp(transform.localScale, v3Scale, Time.deltaTime * shrinkSpeed);
}
if (Input.GetMouseButton(0))
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit) && hit.transform == transform)
{
targetScale = maxScale;
v3Scale = new Vector3(targetScale, targetScale, targetScale);
}
if (automaticScale == false)
transform.localScale = Vector3.Lerp(transform.localScale, v3Scale, Time.deltaTime * shrinkSpeed);
}
if (automaticScale == true)
{
transform.localScale = Vector3.Lerp(transform.localScale, v3Scale, Time.deltaTime * shrinkSpeed);
}
if (rotateOnMouseMove == true)
{
transform.Rotate(Input.GetAxis("Mouse Y") * rotatingSpeed, -Input.GetAxis("Mouse X") * rotatingSpeed, 0, Space.World);
}
if (rotateOnMouseMove == true)
{
rotateOnMouseDrag = false;
}
if (rotateOnMouseDrag == true)
{
rotateOnMouseMove = false;
}
}
private void OnMouseDrag()
{
if (rotateOnMouseDrag == true)
{
transform.Rotate(Input.GetAxis("Mouse Y") * rotatingSpeed, -Input.GetAxis("Mouse X") * rotatingSpeed, 0, Space.World);
}
}
}
The problem is at the bottom:
if (rotateOnMouseMove == true)
{
rotateOnMouseDrag = false;
}
if (rotateOnMouseDrag == true)
{
rotateOnMouseMove = false;
}
Once I'm starting the game by default the rotateOnMouseDrag is set to true. When I click on the check box of rotateOnMoseMove it's switching between them the rotateOnMouseDrag is false and rotateOnMouseMove is true.
The problem is when then I click again on the check box of rotateOnMouseDrag but it's never switching between them again it keep staying true on the rotateOnMouseMove.
I want it to act like a switch each time one of them is true the other should be false.