I’m following a tutorial that you can view at
. I’m using the moving platform script here, but it’s written in Javascript, while I want to use C#. So here’s the C# adaptation I made… and this is the error:
Assets/Enemymovement.cs(31,45): error CS1612: Cannot modify a value type return value of `UnityEngine.Rigidbody2D.velocity’. Consider storing the value in a temporary variable
Script:
using UnityEngine;
using System.Collections;
public class Enemymovement : MonoBehaviour {
public bool what = false;
public int speed = 0;
public int whatway = 0;
public int timer = 0;
public int maxTimer = 50;
// Update is called once per frame
void Update () {
if (what == false) {
if (whatway == 0){
rigidbody2D.velocity.x = -speed;
}
if (whatway == 1){
rigidbody2D.velocity.y = -speed;
}
}
if (what == true) {
if (whatway == 0){
rigidbody2D.velocity.x = speed;
} if (whatway == 1){
rigidbody2D.velocity.y = speed;
}
}
timer += 1;
if (timer >= maxTimer) {
timer = 0;
if (what == false) {
what = true;
timer = 0;
return;
} else if (what == true) {
what = false;
timer = 0;
return;
}
}
}
}
Anyone know how to fix this? I’ve tried switching ‘rigidbody2D’ to ‘Rigidbody2D’ but then I just get another error.