【发布时间】:2021-01-16 19:53:03
【问题描述】:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Platform : MonoBehaviour
{
public float speed = 10.0f;
private Rigidbody2D rb;
// Use this for initialization
void Start()
{
rb = this.GetComponent<Rigidbody2D>();
rb.velocity = new Vector2(-speed, 0);
}
// Update is called once per frame
void Update()
{
//not important
}
private void OnTriggerEnter2D(Collider2D other)
{
//not important
}
}
^^ 这是我的 Platform.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlatformSpawner : MonoBehaviour
{
public GameObject Platform;
public GameObject Fireball;
public float respawnTime = 0.1f;
// Use this for initialization
void Start()
{
StartCoroutine(ObjectSpawning());
}
private void spawnPlatform()
{
//not important
}
private void spawnFireball()
{
//not important
}
IEnumerator ObjectSpawning()
{
while (true)
{
yield return new WaitForSeconds(respawnTime);
spawnPlatform();
spawnFireball();
respawnTime *= 1.02f;
}
}
}
^^ 这是我的 PlatformSpawner.cs
我是 Unity 和 C# 的新手,如何从 PlatformSpawner.cs 更改 Platform.cs 中的 speed 值?我在网上查了一下,但我似乎找不到答案......所以我希望你们能帮助我! 我正在尝试逐渐增加速度值。 提前致谢(:
【问题讨论】: