内容纲要

Npc的对话能力

遇到玩家时候Npc会产生随机对话,但当前只实现了一种对话,因为我不会读取文本
当前状态脚本如下

功能 ;实现遇到玩家产生随机对话

 public class IsTalk : Static//说话状态
    {
        public override void Enter(NpcController owner)
        {

            owner.SpeakText.gameObject.SetActive(true);
            owner.SpeakText.text = "我孩子长得像隔壁老王";
        }
        public override void Updates(NpcController owner)
        {
            owner.gameObject.GetComponent().SetFloat("MDirY", 0);
            owner.gameObject.GetComponent().SetFloat("MDirX", 0);
            owner.gameObject.GetComponent().SetBool("MIsIde", true);
            if (Input.GetKeyDown(KeyCode.J))
            {
                owner.SpeakText.text = "我饿了,不要聊了";
                owner.Invoke("SpeakOver",2f);

            }
        }
    }

同时需要一个感应玩家到来的信息

  1. 首先创建子物体,在子物体中加上圆形触发器,点上Trigger
    2.加入脚本如下

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class IsSees : MonoBehaviour {

    // Use this for initialization
    void Start () {

    }
    // Update is called once per frame
    void Update () {

    }
    public void OnTriggerStay2D(Collider2D collision)
    {
        if (collision.gameObject.tag=="Player")
        {
            gameObject.transform.parent.GetComponent().Changeinit();
            //Debug.Log("111");
        }
    }
    public void OnTriggerExit2D(Collider2D collision)
    {
        if (collision.gameObject.tag=="Player")
        {
            gameObject.transform.parent.GetComponent().IsSeePlayer=false;
            gameObject.transform.parent.GetComponent().Changeinits();
        }
        if (collision.gameObject.tag=="Moster")
        {
            gameObject.transform.parent.GetComponent().MosterTransform = collision.transform;
        }
    }
}

发表评论