2014-11-01 11:57:46 +00:00
|
|
|
|
//The object must have a collider
|
|
|
|
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
2015-04-01 19:26:17 +00:00
|
|
|
|
public class Gui_OnClickedMoveCamera : MonoBehaviour {
|
2014-11-01 11:57:46 +00:00
|
|
|
|
|
|
|
|
|
public Transform destination;
|
2015-04-01 19:26:17 +00:00
|
|
|
|
public Gui_CameraController camCtrl;
|
2014-11-01 11:57:46 +00:00
|
|
|
|
|
2014-11-01 14:20:53 +00:00
|
|
|
|
private Color clrBase;
|
|
|
|
|
private Color clrTarget;
|
|
|
|
|
private Renderer[] children;
|
2015-01-21 23:09:21 +00:00
|
|
|
|
public Canvas canva;
|
2014-11-01 11:57:46 +00:00
|
|
|
|
|
2015-03-04 14:03:15 +00:00
|
|
|
|
void Awake() {
|
2015-03-03 23:03:19 +00:00
|
|
|
|
clrBase = GetComponent<Renderer>().material.color;
|
2014-11-01 14:20:53 +00:00
|
|
|
|
clrTarget = clrBase;
|
|
|
|
|
children = GetComponentsInChildren<Renderer>();
|
2015-01-21 23:09:21 +00:00
|
|
|
|
//canva = destination.GetComponentInChildren (Canvas);
|
2014-11-01 14:20:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-03-04 14:03:15 +00:00
|
|
|
|
void OnMouseDown() {
|
2014-11-01 14:20:53 +00:00
|
|
|
|
//Move to position
|
2015-01-10 15:18:55 +00:00
|
|
|
|
|
2015-01-21 23:09:21 +00:00
|
|
|
|
|
|
|
|
|
|
2014-11-01 11:57:46 +00:00
|
|
|
|
camCtrl.targetPos = destination.position;
|
|
|
|
|
camCtrl.targetRot = destination.rotation;
|
|
|
|
|
}
|
2014-11-01 14:20:53 +00:00
|
|
|
|
|
2015-03-04 14:03:15 +00:00
|
|
|
|
void OnMouseEnter() {
|
2014-11-01 14:20:53 +00:00
|
|
|
|
//Lerp to hilight color
|
|
|
|
|
clrTarget = new Color(1.0F, 0.87F, 0.75F);
|
|
|
|
|
}
|
2015-03-04 14:03:15 +00:00
|
|
|
|
|
|
|
|
|
void OnMouseExit() {
|
2014-11-01 14:20:53 +00:00
|
|
|
|
//Lerp to base color
|
|
|
|
|
clrTarget = clrBase;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-04 14:03:15 +00:00
|
|
|
|
void Update() {
|
2014-11-01 14:20:53 +00:00
|
|
|
|
//Lerp to clrTarget
|
2015-03-03 23:03:19 +00:00
|
|
|
|
Color clr = Color.Lerp(GetComponent<Renderer>().material.color, clrTarget, Time.deltaTime * 10);
|
2014-11-01 14:20:53 +00:00
|
|
|
|
|
|
|
|
|
//Fixme? Any newly created chilren wont be lerped
|
2015-03-04 14:03:15 +00:00
|
|
|
|
foreach(Renderer child in children) {
|
2014-11-01 14:20:53 +00:00
|
|
|
|
child.material.color = clr;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-11-01 11:57:46 +00:00
|
|
|
|
}
|