도움이 필요합니다. 나는이 스크립트는 interactBase과 interactRock 스크립트를Unity3d의 다형성
이 가능하면 저는 잘 모릅니다.
interactRock 스크립트는 interactBase 스크립트를 확장합니다.
interactRock 함수 덮어 쓰기 "상호 작용()"를
그래서 내가 개체의 참조를 얻고 아이의 함수를 호출하려고합니다.하지만 dosent가 작동하는 것 같다. 아마 내가 도와 줄 수 있니?
코드 :
interactBase :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class interactBase : MonoBehaviour {
public interactBase(){
}
// Use this for initialization
void Start() {
}
// Update is called once per frame
void Update() {
}
public void interact(){
}
}
rockInteract :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class rockInteract : interactBase {
public bool triggered;
public rockInteract(){
}
// Use this for initialization
void Start() {
triggered = false;
}
// Update is called once per frame
void Update() {
}
public new void interact(){
triggered = true;
print ("working");
}
}
호출하는 스크립트 :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class triggerScript : MonoBehaviour {
Animator anim;
SpriteRenderer sprite;
public bool triggered;
public GameObject toTrigger;
interactBase baseFunc;
// Use this for initialization
void Start() {
anim = GetComponent<Animator>();
sprite = GetComponent<SpriteRenderer>();
triggered = false;
baseFunc = toTrigger.GetComponent<interactBase>();
print (baseFunc);
}
// Update is called once per frame
void Update() {
transform.position += Vector3.zero;
if (triggered == true) {
//print (baseFunc.interact());
baseFunc.interact();
triggered = false;
}
}
}
당신에게
감사 6,
근무한 (Y) 감사합니다. – Maik