I’ve tried to solve my solution that is scale the green object (cube) by move the blue object(cube)!! But I still couldn’t do it!!
Also I am dragging the blue object by mouse… So the blue object is moving by mouse and then the green object has to scale by the blue object! I’m thinking this way! Maybe will be not right my way!
So anyone can help me please??
This is my Script:
using UnityEngine;
using System.Collections;
public class ScaleByRightCube : MonoBehaviour {
private GameObject mainObject;
private GameObject positionRightCube;
private float positionZ = 5.0f;
public float sizingFactor = 0.03f;
private float startSize;
private float startX;
// Use this for initialization
void Start()
{
mainObject = GameObject.Find("MainObject");
positionRightCube = GameObject.Find("PositionRightCube");
}
// Use this when user has clicked on object and still holding it
void OnMouseDrag()
{
//When user has left clicked
if (Input.GetMouseButton(0))
{
//Move the blue box by mouse
Vector3 positionRight = positionRightCube.transform.position;
Vector3 mousePosition = new Vector3 (Input.mousePosition.x, Input.mousePosition.y, positionZ);
startX = mousePosition.x;
Vector3 objPosition = Camera.main.ScreenToWorldPoint (mousePosition);
//Set the blue box by x axis of mouse and y,z axises of empty-object right one
transform.position = new Vector3(objPosition.x,positionRight.y,positionRight.z);
startSize = mainObject.transform.localScale.z;
}
if(Input.GetMouseButton(0))
{
//Scale green box by blue box
Vector3 size = mainObject.transform.localScale;
size.x = startSize + (Input.mousePosition.x - startX) * sizingFactor;
Debug.Log("Hi, I am the formula to calculate size.x: " + startSize + "+" + "(" + Input.mousePosition.x + "-" + startX + ")" + "*" + sizingFactor + "=" + size.x);
mainObject.transform.localScale = size;
}
}
void OnMouseUp()
{
// Debug.Log("Hi, I am distance :" + distanceObjects);
}
}