当前位置:网站首页>Unity 传送机制的实现
Unity 传送机制的实现
2022-06-11 04:11:00 【海 月】
效果
位置存储

锚点设定

传送界面

传送效果

代码
位置
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu]
public class Locations : ScriptableObject
{
public List<Location> locations;
}位置保存工具
using UnityEditor;
using UnityEngine;
public class LocationSavingTool : Editor
{
public static Locations locationsAsset = Resources.Load<Locations>("Configurations/Locations");
[MenuItem("CONTEXT/Transform/保存位置")]
static void SaveLocationToAsset()
{
GameObject thisObject = Selection.activeGameObject;
locationsAsset.locations.Add(new Location(thisObject.name, thisObject.transform.position));
}
}位置管理器
using UnityEngine;
public class LocationsManager : Singleton<LocationsManager>
{
public Locations locationsAsset = Resources.Load<Locations>("Configurations/Locations");
public Vector3 GetLocationByName(string name)
{
foreach (var i in locationsAsset.locations)
{
if (i.name == name)
{
return i.location;
}
}
return Vector3.zero;
}
}传送
using UnityEngine;
public class Teleport : MonoBehaviour
{
void Start()
{
NotificationCenter.DefaultCenter().AddObserver(this, "PlayerTeleport");
}
public void PlayerTeleport(Notification notification)
{
GameObject player = GameObject.FindGameObjectWithTag("Player");
player.transform.position = (Vector3)notification.data;
}
}传送锚点
using UnityEngine;
public class TeleportPoint : MonoBehaviour
{
public string name;
public void OnClicked()
{
NotificationCenter.DefaultCenter().PostNotification(this, "PlayerTeleport", LocationsManager.Instance.GetLocationByName(name));
}
}边栏推荐
- JVM(4):类的主动使用与被动使用、运行时数据区域内部结构、JVM线程说明、PC寄存器
- PHP正则用例
- Protection and bypass of repeated contracting
- Final review of software engineering notes (short answer)
- Simulation of radar emitter modulated signal
- app直播源码,平台登录页面实现和修改密码页面实现
- Cloud broadcast alert, guanghetong helps intelligent camera to build a "river protection" drowning prevention system
- Guanghetong won the "science and Technology Collaboration Award" of Hello travel, driving two rounds of green industries to embrace digital intelligence transformation
- 为了实现零丢包,数据中心网络到底有多拼?
- What great open source projects does Google have?
猜你喜欢

MySql索引

The live broadcast helped Hangzhou e-commerce Unicorn impact the listing, and the ledger system restructured the new pattern of e-commerce transactions

再聊数据中心网络

June 10, 2022: Captain Shu crosses a sweet potato field from north to South (m long from north to South and N wide from east to West). The sweet potato field is divided into 1x1 squares. He can start

Sslstrip Ultimate - location hijacking

2022 年 5 月产品大事记

Eth Transfer

mysql存储过程

Feature selection algorithm based on bare bones particleswarm optimization

Watson K's Secret Diary
随机推荐
[customview] glide+bitmaptransformation picture upper and lower border wave processing (wavetransformation)
JVM (5): virtual machine stack, stack exception, stack storage result and operation principle, stack internal structure, local variable table
Red team shooting range with three-layer protection
超简单 CameraX 人脸识别效果封装
MySQL lock summary
[laser principle and application-2]: key domestic laser brands
MySQL stored procedure
Market prospect analysis and Research Report of programmable digital temperature regulator in 2022
[激光器原理与应用-2]:国内激光器重点品牌
关于重复发包的防护与绕过
2022 love analysis · privacy computing vendor panoramic report | love Analysis Report
游戏数学: 计算屏幕点中的平面上的点(上帝视角)
2022 年 5 月产品大事记
JVM (1): introduction, structure, operation and lifecycle
A Security Analysis Of Browser Extensions
数据分析师必知必会的统计学知识
未來已來,5G-Advanced時代開啟
D structure as index of multidimensional array
CES 2022 𞓜 guanghetong LTE module fm101 has obtained two important ce/fcc certifications with excellent performance
域名解析耗时是什么?域名解析耗时影响因素有哪些?