27783人加入学习
(125人评价)
如何制作塔防游戏(基于Unity5.5)
价格 免费

有些同学遇到的中间道路也变色的话 可以给中间的加上Way标签 然后用如下的代码

void OnMouseEnter() {
        if (turretGo == null  && EventSystem.current.IsPointerOverGameObject()==false && this.tag !="Way") {
            renderer.material.color = Color.red;
        }
    }
    void OnMouseExit() {
        if (turretGo == null && EventSystem.current.IsPointerOverGameObject() == false && this.tag != "Way") {
            renderer.material.color = Color.white;
        }
    }

[展开全文]

官网api文档中,OnMouseEnter的触发条件之一,是Edit-project settings-Physics-Queries Hit Triggers勾选上。(另一个是物体身上有collider)

以此反推,OnMouseEnter的工作是通过射线检测完成的。同理,OnMouseExit也是

 

PS:在炮塔collider范围内的mapcube在目前的情况中,是不可以被点亮的

[展开全文]