我想编码为,当我的玩家收集5个物品时(因此,当paintCount = 5时),玩家会在短时间内获得一次速度提升,计数器又回到零。但是我什至不知道如何让我的播放器更快。当我想将速度变量乘以2时,它将给出一个错误。欢迎使用任何帮助(在C#中)。
速度变量在我的主脚本中,用于播放运动员的 Action 。
错误:
“只有赋值,调用,递增,递减,等待和新对象表达式可以用作语句。”
using UnityEngine;
using System.Collections;
public class Paintser : PowerUp
{
public static int paintCount = 0;
public void SpeedUp()
{
if (paintCount == 5)
{
SimplePlayer0.speed * 2;
}
}
}
另一类:
using UnityEngine;
using System.Collections;
public class PowerUp : MonoBehaviour
{
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
Destroy(this.gameObject);
Paintser.paintCount++;
}
}
}
最佳答案
SimplePlayer0.speed * 2;
这不是一个有效的赋值,它只是一个乘法,不能独自承受。您需要使用
SimplePlayer0.speed = SimplePlayer0.speed * 2;
要么
SimplePlayer0.speed *= 2;
这两个等效地意味着:将
SimplePlayer0.speed
与2
相乘,然后将结果分配回SimplePlayer0.speed
。
关于c# - 在C#中收集X项时使用SpeedBoost,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28744668/