c# - 在C#中收集X项时使用SpeedBoost

标签 c# visual-studio-2013 unity3d syntax-error

我想编码为,当我的玩家收集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.speed2相乘,然后将结果分配回SimplePlayer0.speed

关于c# - 在C#中收集X项时使用SpeedBoost,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28744668/

相关文章:

c# - 检查 null 线程安全吗?

visual-studio-2013 - Nuget:远程服务器返回错误:(504) 网关超时

c# - 参数未被视为参数 - 可能的路由问题

c# - 将数据 GridView 背景设置为透明

c# - ASP.NET 网络 API : PushStreamContent flush does not flush

c# - 检查玩家是否通过了两个门

unity3d - 无法使用混合现实工具包为可交互游戏对象制作动画

c# - 统一: Collider not resizing with Sprite Shape by Script

c# - Xamarin 形成自定义导航转换

tfs - 如何在 Visual Studio Online 中重新分配工作项?