Coding change from Unity 4 to Unity 5 ??

Hi,

I am a starter, and Previously using Unity 4 for practicing Roll a ball. Now I install Unity5 and while creating the same script there are showing API Update required.

Here is the script :

using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour {

void fixedupdate ()
{
float moveHorizontal = Input.GetAxis(“Horizontal”);
float moveVertical = Input.GetAxis (“Vertical”);

Vector3 movement = new Vector3 (moveHorizontal, 0.0, moveVertical);

rigidbody.AddForce(movement) ;
}
}

Regards,
Priyankar

Welcome to the forum!

Please use code tags whenever you post code:

C# is case sensitive, meaning, it is important use FixedUpdate instead of fixedupdate. The only change in your script is that rigidbody is not anymore available directly. You need to replace it with GetComponent (). If you are looking for more detailed information, that topic was raised several times here in the forum already. There is even a blog post covering exactly your use case:

That change I mentioned regarding rigidbody would be performed automatically if you let the script updater run.

2 Likes

Component quick property accessors were removed. You need to use GetComponent to access them now.

GetComponent<RigidBody>().AddForce(movement);

Hi,

Thanks for the help . Yes I got it. Damn … I made the same mistake I did it last time the Case sensitivity. Thanks a lot to check that out. I will remember it. Also thanks for the “code” tag … I will do the same in future.

Regards,
Priyankar