start() and update() beginner question

hi i have just started using unity a few weeks ago.
i have done the tutorials on spaceshooter and roll the ball tutorial.
when we rotate the cube in the ball game,we do it in the update function.but when we are rotating the asteroid in the spaceshooter, why we can just rotate it in the start function??

this is how we make the asteroid rotate in spaceshooter game:

using UnityEngine;

public class AsteroidMovement : MonoBehaviour {

private Rigidbody rb;
public float tumble;
// Use this for initialization
void Start()
{
rb = GetComponent();
rb.angularVelocity = Random.insideUnitSphere * tumble;
}
}

this is how we make the cube rotate in the ball game :

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class rotator : MonoBehaviour {

// Update is called once per frame

void Update () {

transform.Rotate(new Vector3(15, 30, 45)* Time.deltaTime);

}

}

Welcome to Unity!

Please look at this page for how to post code nicely on the forums, for future reference: Using code tags properly

It’s good that you began with some tutorials. That’s a good start.
The reason they are a bit different, is the first piece of code is setting the angular velocity which will continue during play. It can be modified by other forces, or angular drag, though. This is using the physics system, and works with rigidbodies.

The second code example is modifying the rotation a little at a time, each frame and using the transform (rather than the rigidbody). It’s not using the physics system.

Hope that helps some :slight_smile:

thank you for your reply
so do you mean that setting angular velocity is one time thing,you dont need to keep updating it?

correct

Yes, but as I said, it could be affected by other forces or angular drag which could alter it in some way.
:slight_smile: