1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| public class RoadSign : MonoBehaviour {
public Canvas signCanvas1; public Canvas signCanvas2;
public Canvas signCancas3; public Canvas Terminal;
public bool checkaround; public GameObject aroundcheck; public float checkRadius;
public LayerMask keiji1; public LayerMask keiji2; public LayerMask keiji3; public LayerMask keiji4;
// 在游戏开始时,隐藏画布 private void Start() { signCanvas1.enabled = false; signCanvas2.enabled = false; Terminal.enabled = false; }
// 在每一帧更新时,检测玩家是否靠近或点击路牌 private void Update() { To_show_or_hide_1(); To_show_or_hide_2(); To_show_or_hide_3(); To_show_or_hide_4(); }
// check if show the canvas void To_show_or_hide_1(){
checkaround=Physics2D.OverlapCircle(aroundcheck.transform.position,checkRadius,keiji1); if (checkaround == true){ signCanvas1.enabled = true; } if (checkaround == false){ signCanvas1.enabled = false; } } void To_show_or_hide_2(){
checkaround=Physics2D.OverlapCircle(aroundcheck.transform.position,checkRadius,keiji2); if (checkaround == true){ signCanvas2.enabled = true; } if (checkaround == false){ signCanvas2.enabled = false; } } void To_show_or_hide_3(){
checkaround=Physics2D.OverlapCircle(aroundcheck.transform.position,checkRadius,keiji3); if (checkaround == true){ Terminal.enabled = true; } if (checkaround == false){ Terminal.enabled = false; } }
void To_show_or_hide_4(){
checkaround=Physics2D.OverlapCircle(aroundcheck.transform.position,checkRadius,keiji4); if (checkaround == true){ signCancas3.enabled = true; } if (checkaround == false){ signCancas3.enabled = false; } } private void OnDrawGizmosSelected() { Gizmos.color=Color.blue; Gizmos.DrawWireSphere(aroundcheck.transform.position,checkRadius); } }
|