_xiaofang/xiaofang/Assets/Script/hylScripts/NPCController.cs
2024-12-12 18:51:08 +08:00

42 lines
961 B
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using System.Xml.Linq;
using UnityEngine;
using UnityEngine.UIElements;
public class NPCController : MonoBehaviour
{
public static NPCController instance;
public List<RecuseNpc> npcsList = new List<RecuseNpc>();//存放每个生成的npc的脚本
public GameObject npc;//npc人物预制体
// Start is called before the first frame update
void Start()
{
instance = this;
}
public void InitNPC(Vector3 v,NpcData npcData)
{
// 使用指定的世界坐标位置来实例化 NPC而不是依赖 trans 位置
GameObject go = GameObject.Instantiate(npc, v, Quaternion.identity); // 直接指定位置和旋转
RecuseNpc recuseNpc = go.GetComponent<RecuseNpc>();
recuseNpc.SetNPCInfo(npcData.UserId);//初始化npcid
npcsList.Add(recuseNpc);//将生成的NPC的脚本加入list存放
}
// Update is called once per frame
void Update()
{
}
}