Machineboy空

상속: virtual , override 본문

Computer/개념

상속: virtual , override

안녕도라 2023. 9. 21. 13:40

//부모 Scripts

public class E_Grabbable : MonoBehaviour
{
    E_Grabber hand;
    Rigidbody rb;

    // Start is called before the first frame update
    public virtual void Start()
    {
        rb = GetComponent<Rigidbody>(); 
    }
    
        public virtual void Update()
    {
        if (hand != null)
        {
            transform.position = hand.transform.position;
            transform.rotation = hand.transform.rotation;
        }
    }

    public virtual void DoAction()
    {

    }
}
//자식 Scripts

public class E_Cube : E_Grabbable
{
    // Start is called before the first frame update
    public override void Start()
    {
        base.Start();
    }

    // Update is called once per frame
    public override void Update()
    {
        base.Update();
    }

    public override void DoAction()
    {
        base.DoAction();
        GetComponentInChildren<Renderer>().material.color = Random.ColorHSV();
    }
}

'Computer > 개념' 카테고리의 다른 글

VM(Virtual Machine) 가상 머신  (0) 2023.10.18
배열(Array)과 리스트(List)  (0) 2023.10.11
괄호들: Generic [ ], ( ), { }, < >  (0) 2023.09.20
OOP 객체지향 4가지 원리  (0) 2023.09.08
Data Structure: Queue & Stack  (0) 2023.09.08