1.提示框面板脚本(挂载到Tips):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public enum TipsStyle
{
Style1,
}
public class TipsPanel :MonoBehaviour
{
GameObject styleobj;
public static TipsPanel _instance;
private void Awake()
{
_instance = this;
}
private void Start()
{
styleobj = transform.Find("Style1").gameObject;
}
public void showTips(string content, TipsStyle style)
{
switch (style)
{
case TipsStyle.Style1:
styleobj.SetActive(true);
styleobj.transform.Find("Content").GetComponent<Text>().text = content;
break;
}
}
public void HideTips(TipsStyle style)
{
switch (style)
{
case TipsStyle.Style1:
styleobj.SetActive(false);
break;
}
}
}
2.提示触发器(挂载到InfoSign)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InfoSign : MonoBehaviour
{
public Sprite normalSprite, lightSprite;
SpriteRenderer render;
public string tipContent;
private void Start()
{
render = transform.GetComponent<SpriteRenderer>();
}
public void OnTriggerEnter2D(Collider2D collider)
{
if(collider.tag == "Player")
{
render.sprite = lightSprite;
TipsPanel._instance.showTips(tipContent, TipsStyle.Style1);
}
}
public void OnTriggerExit2D(Collider2D collider)
{
if (collider.tag == "Player")
{
render.sprite = normalSprite;
TipsPanel._instance.HideTips(TipsStyle.Style1);
}
}
}
3.跳跃平台
使用platform effector 2D实现: 1.Use Collider Mask:设置可以与哪些层级(layer)发生碰撞。 2.Rotational Offset:碰撞角度的方向。 3.one way:使用一条路可以穿过该碰撞体,不勾选则默认全可以碰撞 Surface Arc:设置碰撞角度。 4.sides:设置碰撞体摩擦力和反弹力。
|