Unity3d: reusable scripts & tricks

Home  /  Game Development  /  Unity3d: reusable scripts & tricks

- AnimatedTexture
- CameraFollow
- HideCursor
- LookAtPlayer
- MoveFromPointToPoint
- OpenCloseAnimation
- Rotation
- TriggerDestroyObject
- DoorTrigger
- ChangeMaterial
- ShowGUIText
- PlayerMovement
- Laser
- RotationAroundObject
- SlowMotion
- OpenCloseDoor: AttachToDoor / AttachToButton
- NavMeshScript

Other
[RequireComponent(typeof(Rigidbody))]
//===================================
[Range(1.0f, 5.0f)]
public int x; LineRenderer line;
// Call 'methodName' after delay
Invoke("methodName", 2); 
InvokeRepeating("abc",2, 2);

Polymorphism
public class A
{
    void Start()
    {
        Fruit myFruit = new Apple();
        myFruit.SayHello();
        myFruit.Chop();

        Apple myApple = (Apple)myFruit;
        myApple.SayHello();
        myApple.Chop();
    }
}

public class Fruit
{
    public Fruit() { }              //1
    public void Chop() { }          //4
    public void SayHello() { }      //3
}

public class Apple : Fruit
{
    public Apple() { }              //2
    public new void Chop() { }      //6
    public new void SayHello() { }  //5
}

Delegates
delegate void MultiDelegate();
MultiDelegate myMultiDelegate;

void Start()
{
    myMultiDelegate += PowerUp;
    myMultiDelegate += TurnRed;

    if (myMultiDelegate != null)
        myMultiDelegate();
}

void PowerUp() { ... }
void TurnRed() { ... }
Comments are closed.