public bool isLookingAt(PlayerInteractable[] test) { foreach (PlayerInteractable t in test) if (lookingAt == t) return true; return false; }
void OnControllerColliderHit(ControllerColliderHit hit) { if (this.currentState != State.Won) { //hit.gameObject.GetComponent<PlayerInteractable>()?.OnHit(hit, this); PlayerInteractable pi = hit.gameObject.GetComponent <PlayerInteractable>(); if (pi) { pi.OnHit(hit, this); } } }
public void OnTriggerEnter(Collider other) { if (!canMove) { return; } if (other.tag == "PlayerInteractable" || other.tag == "HittableObject") { PlayerInteractable interactable = other.GetComponent <PlayerInteractable>(); interactable.Interact(this.moveableObject); } }
public void OnTriggerEnter(Collider other) { if (!player.isLocalPlayer) { return; } PlayerInteractable p = other.GetComponent <PlayerInteractable>(); if (ValidInteractableObject(p)) { nearby.Insert(0, p); } }
public void OnTriggerExit(Collider other) { if (!player.isLocalPlayer) { return; } PlayerInteractable p = other.GetComponent <PlayerInteractable>(); if (p is CraftingTable) { player.HideCraftItemPanel(); } nearby.Remove(p); }
void OnControllerColliderHit(ControllerColliderHit hit) { if (this.currentState != State.Won) { //hit.gameObject.GetComponent<PlayerInteractable>()?.OnHit(hit, this); PlayerInteractable pi = hit.gameObject.GetComponent <PlayerInteractable>(); if (pi) { if (pi.GetType() == typeof(Killing)) { gameManager.CountDeath(); gameManager.RespawnPlayer(); } pi.OnHit(hit, this); } } }
void OnControllerColliderHit(ControllerColliderHit hit) { if (this.currentState != State.Won) { PlayerInteractable pi = hit.gameObject.GetComponent <PlayerInteractable>(); if (pi) { pi.OnHit(hit, this); ///////////////////////////////////////////////////////// if (pi.GetComponent <Killing>()) { Toolbox.GetInstance().GetManager <GameManager>().AddSceneTime(); Toolbox.GetInstance().GetManager <GameManager>().AddDiedCount(); Toolbox.GetInstance().GetManager <GameManager>().Respawn(); } ///////////////////////////////////////////////////////// } } }
// Use this for initialization void Start() { playerInteractable = GetComponent <PlayerInteractable>(); // We don't need to check whether playerInteractable is null because of the RequireComponent above. if (gameObjectToHighlight == null) { Debug.LogWarning("HighlightWhenPlayerInTrigger:Start() - No gameObjectToHighlight set."); return; } else { mat = gameObjectToHighlight.GetComponent <Renderer>().material; highlightColor = mat.GetColor("_BorderColor"); outlineWidth = mat.GetFloat("_Border"); mat.SetFloat("_OutlineFront", 0f); mat.SetFloat("_Border", 0f); } inited = true; }
void Start() { playerInteractable = GetComponent <PlayerInteractable>(); playerInteractable.PlayerInteractedAction = (player) => { player.PickUpCrystal(this); }; playerInteractable.CanPlayerInteract = (player) => { return(player.IsHoldingACrystal == false); }; var renderer = GetComponentInChildren <Renderer>(); switch (crystalType) { case CrystalType.AND: renderer.material = andMaterial; break; case CrystalType.XOR: renderer.material = orMaterial; break; case CrystalType.BLOCKING: renderer.material = blockingMaterial; break; } }
void Start() { PlayerInteractable playerInteractable = GetComponent <PlayerInteractable>(); playerInteractable.PlayerInteractedAction = (player) => { if (player.IsHoldingACrystal) { var oldMountedCrystal = mountedCrystal; player.SetCrystalInMount(this); if (oldMountedCrystal) { player.PickUpCrystal(oldMountedCrystal); } } else { player.PickUpCrystal(mountedCrystal); mountedCrystal = null; } }; playerInteractable.CanPlayerInteract = (player) => { return(player.IsHoldingACrystal || mountedCrystal); }; activatedLightRay = GetComponentInChildren <LightRay>(true); activatedLightRay.transform.position = LightRayOrigin; activatedLightRay.transform.rotation = LightRayRotation; activatedLightRay.gameObject.SetActive(false); if (mountedCrystal) { AcceptCrystal(mountedCrystal); } }
private void Start() { PlayerInteractable glyphinteractive = GetComponent <PlayerInteractable>(); glyphinteractive.PlayerInteracted += Glyphinteractive_PlayerInteracted; }
public void UnregisterInteractableInRange(PlayerInteractable interactable) { interactablesInRange.Remove(interactable); }
private bool ValidInteractableObject(PlayerInteractable p) { return(p != null && (p as MonoBehaviour).isActiveAndEnabled && !nearby.Contains(p) && p.InteractableActive); }
public bool isLookingAt(PlayerInteractable test) { return (lookingAt == test); }
void Awake() { PlayerInteractable playInt = GetComponent <PlayerInteractable>(); playInt.Register(this); }
private void Start() { PlayerInteractable interactiveSound = GetComponent <PlayerInteractable>(); interactiveSound.PlayerInteracted += PlaySound_PlayerInteracted; }
void Update() { if (game.gameState() != GameState.Play && game.gameState() != GameState.ExitingLevel) return; // Every frame, the cursor updates what interactable thing it's looking at // This is done by raycasting into the scene while ignoring the player / raycastignored // ~( (1 << 8) | (1 << 9) ) is a layermask which ignores those above two layers selectively // If we find a PlayerInteractable object within range, but it says it's disabled, ignore it RaycastHit hit; Ray ray = game.playerCamera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0)); Physics.Raycast(ray, out hit, interactDistance, ~( (1 << 8) | (1 << 2) )); PlayerInteractable current = null; if (hit.transform != null) current = hit.transform.GetComponent<PlayerInteractable>(); if (current != null && !current.isInteractable()) current = null; lookingAt = current; // If the player isn't grabbing anything, and they left click while looking at something interactable, // they need to either begin grabbing it (if it's PlayerGrabbable) or simply send it an interact signal if (grabbing == null) { if (Input.GetButtonDown("Mouse Left Click") && lookingAt != null) { if (lookingAt is PlayerGrabbable) { grabbing = (PlayerGrabbable) lookingAt; grabTime = Time.time; grabPosition = grabbing.holdPosition; transform.localPosition = grabPosition; grabbing.transform.parent = transform; grabbing.interact(0); grabJoint.connectedBody = hit.rigidbody; lookingAt = null; } else lookingAt.interact(0); } } // Check if the grabbed object should be released. Multiple conditions satisfy this: // 1) The user presses LMB (dropped release) // 2) The user presses RMB (thrown release) // 3) The object becomes noninteractable // 4) After snapTime, the object's distance from the grabber becomes greater than snapDistance else { if (grabPosition != grabbing.holdPosition) { grabPosition = grabbing.holdPosition; grabbing.transform.parent = null; transform.localPosition = grabPosition; grabbing.transform.parent = transform; } if ((Input.GetButtonDown("Mouse Left Click")) || (Input.GetButtonDown("Mouse Right Click")) || (!grabbing.isInteractable()) || (Time.time > grabTime + snapTime && Vector3.Distance(transform.position, grabbing.transform.position) > snapDistance)) { grabbing.transform.parent = null; grabbing.interact(1); grabJoint.connectedBody.velocity = game.player.getPhysicalVelocity(); if (Input.GetButtonDown("Mouse Right Click")) grabJoint.connectedBody.AddForce(transform.rotation * Vector3.forward * throwForce); grabJoint.connectedBody = null; grabbing = null; } } // Make the grabber bob with the camera Vector3 target = grabPosition - (transform.parent.localPosition - new Vector3(0, 1.5f, 0)) * 0.5f; transform.localPosition = Vector3.Lerp(transform.localPosition, target, 0.5f); }