akadoc/Assets/scripts/Gui_OnClickedMoveCamera.cs

53 lines
1.1 KiB
C#
Raw Normal View History

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
private Color clrBase;
private Color clrTarget;
private Renderer[] children;
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;
clrTarget = clrBase;
children = GetComponentsInChildren<Renderer>();
//canva = destination.GetComponentInChildren (Canvas);
}
2015-03-04 14:03:15 +00:00
void OnMouseDown() {
//Move to position
2014-11-01 11:57:46 +00:00
camCtrl.targetPos = destination.position;
camCtrl.targetRot = destination.rotation;
}
2015-03-04 14:03:15 +00:00
void OnMouseEnter() {
//Lerp to hilight color
clrTarget = new Color(1.0F, 0.87F, 0.75F);
}
2015-03-04 14:03:15 +00:00
void OnMouseExit() {
//Lerp to base color
clrTarget = clrBase;
}
2015-03-04 14:03:15 +00:00
void Update() {
//Lerp to clrTarget
2015-03-03 23:03:19 +00:00
Color clr = Color.Lerp(GetComponent<Renderer>().material.color, clrTarget, Time.deltaTime * 10);
//Fixme? Any newly created chilren wont be lerped
2015-03-04 14:03:15 +00:00
foreach(Renderer child in children) {
child.material.color = clr;
}
}
2014-11-01 11:57:46 +00:00
}