I have an assignment that to create a puzzle game. I have made an pretty good progress so far. Currently, I have made a script that change grabbed object size with E and Q and I assign it to every object that the player can grab.
The problem is that when I press Q and E, its changed every object in the screen including the grabbed one.
How can I fix it? Please help.
Here the code:
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(MeshCollider))]
public class MouseDragAndResizing: MonoBehaviour
{
private Vector3 screenPoint;
private Vector3 offset;
void OnMouseDown()
{
screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
}
void OnMouseDrag()
{
Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
transform.position = curPosition;
}
void Update()
{
if(Input.GetKeyDown(KeyCode.E) && transform.localScale.x < 3 && transform.localScale.y < 3 && transform.localScale.z < 3)
{
transform.localScale = transform.localScale + new Vector3(0.5f, 0.5f, 0.5f);
}
if (Input.GetKeyDown(KeyCode.Q) && transform.localScale.x > 0.5 && transform.localScale.y > 0.5 && transform.localScale.z > 0.5)
{
transform.localScale = transform.localScale + new Vector3(-0.5f, -0.5f, -0.5f);
}
else if (transform.localScale.x < 0.5 && transform.localScale.y < 0.5 && transform.localScale.z < 0.5)
{
transform.localScale = Vector3.zero;
}
}
}