Sample project to showcase the use of UI Toolkit for Runtime based on the Unity Royale project.
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

42 行
1.1 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UnityRoyale
{
//A static, non-moving obstacle that disappears on its own after a while
public class Obstacle : Placeable
{
[HideInInspector] public float timeToRemoval;
private AudioSource audioSource;
private void Awake()
{
pType = Placeable.PlaceableType.Obstacle;
faction = Placeable.Faction.None; //faction is always none for Obstacles
audioSource = GetComponent<AudioSource>();
}
public void Activate(PlaceableData pData)
{
timeToRemoval = pData.lifeTime;
dieAudioClip = pData.dieClip;
//TODO: add more as necessary
StartCoroutine(Die());
}
private IEnumerator Die()
{
yield return new WaitForSeconds(timeToRemoval);
audioSource.PlayOneShot(dieAudioClip, 1f);
if(OnDie != null)
OnDie(this);
Destroy(this.gameObject);
}
}
}