unity——FPS Microgame 代码解析(片段)

1.准心判定

2.UI提示

2.1 开头标题提示

  • 在主界面的canvas划定区域给DisplayMessage,挂上UITable脚本:
    在这里插入图片描述
  • UI Table代码:
    在这里插入图片描述
using UnityEngine;

namespace Unity.FPS.UI
{
   
    // The component that is used to display the Objectives, the Notification and the game messages like a list
    // When a new one is created, the previous ones move down to make room for the new one

    public class UITable : MonoBehaviour
    {
   
        [Tooltip("How much space should there be between items?")]
        public float Offset;

        [Tooltip("Add new the new items below existing items.")]
        public bool Down;

        public void UpdateTable(GameObject newItem)
        {
   
            if (newItem != null)
                newItem.GetComponent<RectTransform>().localScale = Vector3.one;

            float height = 0;
            for (int i = 0; i < transform.childCount; i++)
            {
   
                RectTransform child = transform.GetChild(i).GetComponent<RectTransform>();
                Vector2 size = child.sizeDelta;
                height += Down ? -(1 - child.pivot.y) * size.y : (1 - child.pivot.y) * size.y;
                if (i != 0)
                    height += Down ? -Offset : Offset;

                Vector2 newPos = Vector2.zero;

                newPos.y = height;
                newPos.x = 0;//-child.pivot.x * size.x * hi.localScale.x;
                child.anchoredPosition = newPos;
            }
        }
    }
}

  • 空物体上挂载脚本
  • 有两个脚本 一个是大类objective,一个是使用objective的objectiveKillEnemies。
  • title的Objective代码片:
using System;
using UnityEngine;

namespace Unity.FPS.Game
{
   
    public abstract class Objective : MonoBehaviour
    {
   
        [Tooltip("Name of the objective that will be shown on screen")]
        public string Title;

       
        protected virtual void Start()
        {
   
            DisplayMessageEvent displayMessage = Eve
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值