void Update() { if (InputManager.GetButtonDown("Use")) { InteractObj tempCast = CastObj(); if (tempCast != null && tempCast.CanDirectInteraction) { tempCast.OnInteractObject(); print("YeeeBOY"); } else { print("FUCKOFF"); } } }
void Start() { // 如果需要跟随其他物体 if (followOther != null) { followOtherOffset = this.transform.position - followOther.transform.position; } if (overrideInteactTime) { InteractObj = GetComponent <InteractObj>(); InteractObj.isTimeOverrided = true; } childrenObj = this.GetComponentsInChildren <Transform>(); // 将所有的mask设置为default ChangeLayerMask("Default"); }
private InteractObj CastObj() { Vector3 rayOrigin = mainCam.ViewportToWorldPoint(new Vector2(0.5f, 0.5f)); Vector3 rayDirection = mainCam.transform.forward * 1.5f; RaycastHit rayHit = new RaycastHit(); if (Physics.Raycast(rayOrigin, rayDirection, out rayHit, 2f)) { InteractObj tempObj = rayHit.collider.GetComponent <InteractObj>(); if (tempObj != null) { return(tempObj); } else { return(null); } } else { return(null); } }
void Start() { interactObj = GetComponent <InteractObj>(); offset = this.transform.position - TargetObj.transform.position; }