using UnityEngine;
using System.Collections;
public class MouseRayChangeColor : MonoBehaviour {
private GameObject game;
private Color cubecolor;
private RaycastHit hit;
private RaycastHit hitchangecolor;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//RaycastHit hit;
if(Input.GetMouseButtonDown(0)){
if(game!=null){//重置颜色
Physics.Raycast (Camera.main.ScreenPointToRay(Input.mousePosition),out hitchangecolor);
if(!hitchangecolor.collider.gameObject.name.Contains("Plane")){
game.gameObject.GetComponent<MeshRenderer> ().material.color = cubecolor;
}
}
Physics.Raycast (Camera.main.ScreenPointToRay(Input.mousePosition),out hit);
if(!hit.collider.gameObject.name.Contains("Plane")){
cubecolor = hit.collider.GetComponent<MeshRenderer> ().material.color;
}
if(!hit.collider.name.Contains("Plane")){
hit.collider.GetComponent<MeshRenderer> ().material.color = Color.red;
game = hit.collider.gameObject;
}
//hitchangeposition = hit;
// if(hit.collider.name.Contains("Plane")){
// Vector3 temp = Vector3.Lerp (game.transform.position,hit.point,Time.deltaTime);
// game.transform.position = new Vector3 (temp.x,0.5f,temp.z);
//
// }
}
if(hitchangecolor.collider){
Vector3 temp = Vector3.Lerp (game.transform.position,hitchangecolor.point,Time.deltaTime);
game.transform.position = new Vector3 (temp.x,0.5f,temp.z);
}
}
}
using System.Collections;
public class MouseRayChangeColor : MonoBehaviour {
private GameObject game;
private Color cubecolor;
private RaycastHit hit;
private RaycastHit hitchangecolor;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//RaycastHit hit;
if(Input.GetMouseButtonDown(0)){
if(game!=null){//重置颜色
Physics.Raycast (Camera.main.ScreenPointToRay(Input.mousePosition),out hitchangecolor);
if(!hitchangecolor.collider.gameObject.name.Contains("Plane")){
game.gameObject.GetComponent<MeshRenderer> ().material.color = cubecolor;
}
}
Physics.Raycast (Camera.main.ScreenPointToRay(Input.mousePosition),out hit);
if(!hit.collider.gameObject.name.Contains("Plane")){
cubecolor = hit.collider.GetComponent<MeshRenderer> ().material.color;
}
if(!hit.collider.name.Contains("Plane")){
hit.collider.GetComponent<MeshRenderer> ().material.color = Color.red;
game = hit.collider.gameObject;
}
//hitchangeposition = hit;
// if(hit.collider.name.Contains("Plane")){
// Vector3 temp = Vector3.Lerp (game.transform.position,hit.point,Time.deltaTime);
// game.transform.position = new Vector3 (temp.x,0.5f,temp.z);
//
// }
}
if(hitchangecolor.collider){
Vector3 temp = Vector3.Lerp (game.transform.position,hitchangecolor.point,Time.deltaTime);
game.transform.position = new Vector3 (temp.x,0.5f,temp.z);
}
}
}