Unity C# Code Examples

Debugging

Basic debug logging

Debug.Log("Hello from Unity!");
Debug.Log("Player health: " + 10);
Debug.Log("The time since start: " + Time.time);

Warnings logging

Debug.LogWarning("Warning: Object not found!");

Error logging

Debug.LogError("Critical error: Object not found!");
Object Rotation

Spin windmill continuously

public float rotationSpeed = 50f;
    
    void Update()
    {
        transform.Rotate(Vector3.forward * rotationSpeed * Time.deltaTime);
    }

Spin with axis as variable

public Vector3 rotationAxis = Vector3.up;
    public float speed = 100f;
    
    void Update()
    {
        transform.Rotate(rotationAxis * speed * Time.deltaTime);
    }