Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Coding change from Unity 4 to Unity 5 ??

Discussion in 'Getting Started' started by Priyankar, Mar 29, 2015.

  1. Priyankar

    Priyankar

    Joined:
    Jan 2, 2015
    Posts:
    3
    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
     
  2. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Welcome to the forum!

    Please use code tags whenever you post code:
    http://forum.unity3d.com/threads/using-code-tags-properly.143875/

    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 <Rigidbody> (). 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:
    http://blogs.unity3d.com/2014/06/23/unity5-api-changes-automatic-script-updating/

    That change I mentioned regarding rigidbody would be performed automatically if you let the script updater run.
     
    Kiwasi and Ryiah like this.
  3. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,701
    Component quick property accessors were removed. You need to use GetComponent to access them now.
    Code (csharp):
    1. GetComponent<RigidBody>().AddForce(movement);
     
  4. Priyankar

    Priyankar

    Joined:
    Jan 2, 2015
    Posts:
    3
    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