Unity 定时器

Unity 定时器

🎮

定时器

  1. 关键在于如何去理解Time.deltaTime
    【时间的流逝】🥁

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SocialPlatforms;

public class Emitter : MonoBehaviour
{
public GameObject cube;
public GameObject[] emitter;
public Material[] cubeMaterials;
public float timer = 1.0f;
void Start()
{

}

// Update is called once per frame
void Update()
{
timer -= Time.deltaTime;
if (timer < 0)
{
Vector3 cubePosition = emitter[Random.Range(0, 4)].transform.position;
Instantiate(cube);
cube.transform.position = cubePosition;
cube.GetComponent<MeshRenderer>().material = cubeMaterials[Random.Range(0, 4)];
timer = 2.0f;
print("1");
}
}
}
作者

发布于

2022-09-12

更新于

2023-01-10

许可协议