- Home /
Unity standard Assets is recieveing error
I made a simple scene consisting of unity standard assets 2d. It consits of 3 ground sprites (prototype-grey) with box collider (Slippery). i also added a 2d character from standard assets. I am following the unity tutorial here (http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/infinite-runner). I am trying to run my game but i keep recieving script errors such as this one : Assets/SampleAssets/2D/Scripts/PlatformerCharacter2D.cs(72,17): error CS0619: UnityEngine.Component.rigidbody2D' is obsolete:
Property rigidbody2D has been deprecated. Use GetComponent() instead. (UnityUpgradable)' Any help appreciated?
Answer by illogicalcrow · Mar 19, 2015 at 02:06 PM
Replace
rigidbody2D
with
GetComponent<Rigidbody2D>()
example
GetComponent<Rigidbody2D>().velocity = transform.up * speed;
Alternatively you can cache the components like before by storing the component in a variable.
Rigidbody2D body;
void Start()
{
body = GetComponent<Rigidbody2D>();
}
If performance isn't an issue Unity will automatically do this via the API updater. You can find it in the menu bar at Assets -> Run API Updater
This is part of a change targeting multiple accessors:
Removed quick property accessors, like .rigidBody, .rigidbody2D, .camera, .light, .animation, .constantForce, .renderer, .audio, .networkView, .guiTexture, .collider, .collider2D, .particleSystem, .particleEmitter, .guiText, .hingeJoint for modularization. Instead, use GetComponent to get references.
Read more about it here: http://blogs.unity3d.com/2014/06/23/unity5-api-changes-automatic-script-updating/
If you are new to Unity there is a set of basic scripting tutorials including one on GetComponent usage here.
Thank you that did it. I just downloaded Unity 4 yesterday, previously worked with Unity 4. Didn't know about the api changes. Thx a lot
Your answer
