Search code examples
c#unityscriptunity-game-engine

Convert Code from Unity 4 To Unity 5


I am new to installed Unity 5. where i have some problem in code.

if (transform.parent.rigidbody) parentMagnitude = transform.parent.rigidbody.velocity.magnitude * 0.05f;


Solution

  • You can't access rigidbody with your old shorthand code.

        Rigidbody rb = transform.parent.GetComponent<Rigidbody>();
        if(rb != null) {
            parentMagnitude = rb.velocity.magnitude * 0.05f;
        }