void OnEnable() { OnObjectTouched += TryAttachObject; }
void OnDisable() { OnObjectTouched -= TryAttachObject; }
private void Update() { Vector3 uV = new Vector3(0.0f, -1.0f, 0.0f); Ray ray = new Ray(transform.position, transform.forward); if (pI.IsStrafingRight) { ray = new Ray(transform.position, Quaternion.AngleAxis( 90, transform.forward) * uV); } else if (pI.IsStrafingLeft) { ray = new Ray(transform.position, Quaternion.AngleAxis( -90, transform.forward) * uV); } else if (pI.IsWalkingBack) { ray = new Ray(transform.position, -transform.forward); } IsColliding = Physics.Raycast(ray, out currentWorldObject, pI.MoveDistance, ~0, QueryTriggerInteraction.Ignore); if (!pI.CanInput) { if (pI.Bump) { GameObject temp = currentWorldObject.transform?.gameObject; temp?.GetComponent <BreakingWall>()?.Break(); } return; } if (IsColliding) { // Definetly change this to do it one time. ObjectTouched = currentWorldObject.transform.gameObject; // This could be better if ((ObjectTouched.layer == 8) || (ObjectTouched.layer == 9)) { objectHolder = ObjectTouched.GetComponent <DataHolder>(); objectData = objectHolder?.GetData(inventory.equipedItem); mD.DisplayMessage(objectData); } } else { IsColliding = false; objectData = null; ObjectTouched = null; mD.CleanMessage(); } if ((ObjectTouched != null) && !pI.IsStrafingLeft && !pI.IsStrafingRight) { if (!pI.IsWalking && pI.IsInteracting && IsColliding) { if (objectData == null) { return; } switch (objectData.InteractionType) { case InteractionType.isGrabable: inventory.AddItem(objectData as ItemData); objectHolder.DestroyObject(); mD.CleanMessage(); objectData = null; break; case InteractionType.isUsable: interactor = ObjectTouched.GetComponent <ManualInteractor>(); InteractionResult itemused = interactor.Toggle( inventory?.equipedItem, transform.position); switch (itemused) { case InteractionResult.WrongIntMessage: StartDialogue(wrongInteaction); break; case InteractionResult.UseItem: inventory.ClearEquiped(); break; } break; case InteractionType.isExit: interactor = ObjectTouched.GetComponent <ManualInteractor>(); interactor.Toggle( inventory?.equipedItem, transform.position); break; case InteractionType.isNPC: StartDialogue((objectData as NpcData).Dialogue); break; default: print("Porque é que essa coisa é trigger ?"); break; } } pI.IsInteracting = false; } }