如何从其他脚本更改此值?统一C#
^^ 这是我的平台产卵器.cs如何从其他脚本更改此值?统一C#,c#,unity3d,C#,Unity3d,^^ 这是我的平台产卵器.cs 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()
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
}
}
我是unity和C#的新手,如何更改PlatformSpawner.cs中PlatformSpawner.cs的值speed?我在网上查了一下,但似乎找不到答案。。。所以我希望你们能帮助我!
顺便说一句,我正试图逐渐增加速度值。
提前感谢(:您想只更改一个平台的速度,还是更改所有平台的速度 如果您希望所有平台的速度相同,则应将
速度设置为静态
公共静态浮动速度=10.0f;
然后你可以像这样调整速度
Platform.speed=15.0f;//用所需的速度替换15.0f。
如果要更改特定平台的速度,请从游戏对象中获取platform
组件,然后修改速度
//假设“平台”是gameObject类型
platform.GetComponent().speed=15.0f;//将15.0f替换为所需的速度。
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;
}
}
}