//Author: Ben Stern /// <summary> /// Attempt to empty the item in this container into something else /// </summary> /// <param name="itemToEmptyInto">an interactable Item containing</param> public void EmptyInto(InteractableBase itemToEmptyInto) { bool completed = false; for (int i = 0; i < itemsHolding.Count; i++) { itemToEmptyInto.Interact("Place Item", itemsHolding[i]); // Allows for the spatula to move onto the frying pan and plate itemToEmptyInto.Interact("Take Egg", interactableComponent); itemToEmptyInto.Interact("Place On Plate", itemsHolding[i]); //double check that the item is no longer in this container befor editing properties. if (itemsHolding[i].transform.parent != transform) { itemsHolding.RemoveAt(i); i--; completed = true; continue; } completed = false; } if (completed) { //remove the empty into interaction from the list interactableComponent.RemoveInteractionFromList("Empty into"); } if (HoldingWater) { if (itemToEmptyInto.gameObject.name == "Strainer") { itemToEmptyInto.Interact("Empty water", interactableComponent); } else { itemToEmptyInto.Interact("Fill water", interactableComponent); EmptyWater(); } } }
protected void Interacting() { if (interactTarget != null) { interactTarget?.Interact(this); if (interactTarget.GetComponent <HyperSeed>() != null) { _animator.SetBool("getHyperSeedAni", true); } else if (interactTarget.GetComponent <OreVein>() != null) { _animator.SetBool("getAmmoAni", true); } interactTarget = null; lastInteract = Time.fixedTime; } currentState = PlayerState.Neutral; }
private void Pulse() { //Pulse can only be activated when the vitality is sufficient. Otherwise, play a "cannot do this" sound. if (vitality > threshold && Vector3.Distance(player.transform.position, transform.position) < 5f) { Instantiate(pulse, transform.position, Quaternion.identity); vitality -= pulseCost; //Search for interactables and activate them: Collider[] pulseHits = Physics.OverlapSphere(transform.position, pulseRange); for (int i = 0; i < pulseHits.Length; i++) { InteractableBase interactable = pulseHits[i].GetComponent <InteractableBase>(); if (interactable) { interactable.Activate(); } else { //Check for interactables in parents interactable = pulseHits[i].GetComponentInParent <InteractableBase>(); if (interactable) { interactable.Activate(); } else { //Last resort: check for interactables in children. interactable = pulseHits[i].GetComponentInChildren <InteractableBase>(); if (interactable) { interactable.Activate(); } } } } } else if (Vector3.Distance(player.transform.position, transform.position) < 5f) { AudioSource.PlayClipAtPoint(noPulseClip, transform.position); } }
void Start() { m_NavAgent = GetComponent <NavMeshAgent>(); DebugUtility.HandleErrorIfNullGetComponent <NavMeshAgent, EnemyCharacterController>(m_NavAgent, this, gameObject); m_PlayerTransform = PlayerManager.instance.player.transform; m_PlayerInteractableBase = PlayerManager.instance.player.GetComponent <InteractableBase>(); m_SelfInteractableBase = GetComponent <InteractableBase>(); m_NavAgent.stoppingDistance = 0; m_CharacterStatsController = GetComponent <CharacterStatsController>(); m_cdr = m_CharacterStatsController.cdr.GetValue(); m_moveSpeed = m_CharacterStatsController.moveSpeed.GetValue(); m_NavAgent.speed = m_moveSpeed; m_strategy.selfGameObject = gameObject; m_strategy.playerGameObject = PlayerManager.instance.player; m_strategy.Init(); ChaseOnBeingAttacked(); }
void OnShoot() { PlayerSpellsManager playerSpellsManager = m_ProjectileBase.owner.GetComponent <PlayerSpellsManager>(); PlayerCharacterController playerCharacterController = m_ProjectileBase.owner.GetComponent <PlayerCharacterController>(); Ray ray = playerSpellsManager.spellCamera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) { InteractableBase interactable = hit.collider.GetComponent <InteractableBase>(); if (interactable != null) { print(string.Format("clicking {0}", hit.collider.name)); playerCharacterController.SetFocus(interactable); } else { print("not interactable"); } } }
public override void Init() { m_SpellManager = selfGameObject.GetComponent <EnemySpellsManager>(); m_SelfController = selfGameObject.GetComponent <EnemyCharacterController>(); m_Params = selfGameObject.GetComponent <StrategyParams>(); m_SelfStats = selfGameObject.GetComponent <CharacterStatsController>(); m_PlayerController = playerGameObject.GetComponent <PlayerCharacterController>(); m_PlayerStats = playerGameObject.GetComponent <PlayerStatsController>(); m_SelfStats.onHealthChanged += UpdateDamageTime; m_DelayBetweenAttacks = m_SelfController.delayBetweenAttacks; m_cdr = m_SelfStats.cdr.GetValue(); m_GFX = selfGameObject.transform.Find("GFX").gameObject; m_MobileHealthBar = m_GFX.transform.Find("MobileHealthBar").gameObject; m_EnemyGraphic = m_GFX.transform.Find("EnemyGraphic").gameObject; m_TheHangingGraphic = m_EnemyGraphic.transform.Find("Rope").gameObject; m_Level = LevelsManager.instance.level; m_Animator = selfGameObject.GetComponent <EnemyAnimator>(); m_PlayerInteractable = playerGameObject.GetComponent <InteractableBase>(); PlayerManager.instance.playerDamageTaken += (dmg) => { m_DamageBalanced += dmg; }; EnemyManager.instance.enemyDamageTaken += (dmg) => { m_DamageBalanced -= dmg; }; }
void FixedUpdate() { RaycastHit hit; if (Physics.Raycast(headTransform.position, headTransform.TransformDirection(Vector3.forward), out hit, 5)) { //Don't do anything if its already got it if (currentHit != hit.collider.gameObject) { currentHit = hit.collider.gameObject; //Get parent if current does not have it InteractableBase inter = currentHit.GetComponent <InteractableBase>(); inter = inter == null?currentHit.GetComponentInParent <InteractableBase>() : inter; if (currentInteractable != null) { MoveOffInteract(); currentInteractable = null; } if (inter != null) { currentInteractable = inter; MoveOnInteract(); } } } else { if (currentInteractable != null) { MoveOffInteract(); } currentHit = null; currentInteractable = null; } }
/// Author: Ben Stern /// <summary> /// Attempt to select an object or interact with it in some way /// </summary> /// <param name="selectedObject">The is attempting to be selected</param> public void ObjectSelected(SelectableObject selectedObject) { if (currentSelection == null) { selectedObject.selected = true; currentSelection = selectedObject; selectionIcon.color = selectedObject.GetComponent <Image>().color; selectionIcon.sprite = selectedObject.GetComponent <Image>().sprite; } else { //TODO: call interactable object methods InteractableBase currentInteractable = currentSelection.GetComponent <InteractableBase>(); InteractableBase selectedInteractable = selectedObject.GetComponent <InteractableBase>(); if (currentInteractable != null && selectedInteractable != null) { if (selectedObject.name == "Plate" && selectedObject.transform.childCount >= 1 && (currentSelection.gameObject.GetComponent <SpaghettiScript>() != true && currentSelection.gameObject.GetComponent <MeatballScript>() != true && currentSelection.gameObject.GetComponent <SauceScript>() != true)) { ClearSelection(); } else if ((currentSelection.name == "Spatula" && selectedObject.name == "Frying Pan") || (currentSelection.name == "Spatula" && selectedObject.name == "Plate")) { selectedInteractable.AttemptInteraction(currentInteractable); } else if (selectedInteractable.AttemptInteraction(currentInteractable)) { ClearSelection(); } } } }
/// Author: Kyle Weekley, John Vance /// <summary> /// Attempt to select an object or interact with it in some way /// Added so that the objects in the cafeteria scene can be selected in interacted with /// </summary> /// <param name="selectedObject">The is attempting to be selected</param> public void ObjectSelected(SelectableObject selectedObject) { if (currentSelection == null) { selectionIcon = GameObject.Find("Selection Sprite").GetComponent <Image>(); selectedObject.selected = true; currentSelection = selectedObject; selectionIcon.color = selectedObject.GetComponent <Image>().color; selectionIcon.sprite = selectedObject.GetComponent <Image>().sprite; } else { //TODO: call interactable object methods InteractableBase currentInteractable = currentSelection.GetComponent <InteractableBase>(); InteractableBase selectedInteractable = selectedObject.GetComponent <InteractableBase>(); if (currentInteractable != null && selectedInteractable != null) { if ((currentSelection.name == "Spatula" && selectedObject.name == "Frying Pan") || (currentSelection.name == "Spatula" && selectedObject.name == "Plate")) { selectedInteractable.AttemptInteraction(currentInteractable); } else if (selectedInteractable == currentInteractable) { ClearSelection(); } else if (selectedInteractable.AttemptInteraction(currentInteractable)) { CheckOrder(); ClearSelection(); } } } }
InteractableBase FindUsableInteracable() { //Debug.Log("List of Interactables: "); Collider2D[] closeColliders = Physics2D.OverlapCircleAll(transform.position, 0.8f); InteractableBase closestInteractable = null; float angleToClosestInteractble = Mathf.Infinity; for (int i = 0; i < closeColliders.Length; ++i) { //Debug.Log(i + ": " + closeColliders[i].name); InteractableBase colliderInteractable = closeColliders[i].GetComponent <InteractableBase>(); if (colliderInteractable == null) { continue; } Vector3 directionToInteractble = closeColliders[i].transform.position - transform.position; float angleToInteractable = Vector3.Angle(m_MovementModel.GetFacingDirection(), directionToInteractble); //Debug.Log(i + ": " + closeColliders[i].name + " - " + angleToInteractable); //Debug.Log(m_MovementModel.GetDirection() + " - " + directionToInteractble); if (angleToInteractable < 40) { if (angleToInteractable < angleToClosestInteractble) { closestInteractable = colliderInteractable; angleToClosestInteractble = angleToInteractable; } } } return(closestInteractable); }
//author: John Vance, Ben Stern /// <summary> /// Gets the Frying Pan to be used elsewhere /// </summary> /// <param name="pan">The container that the utensil is being used on</param> public void HoldItem(InteractableBase pan) { currentContainer = pan; //move the item into the container transform.position = currentContainer.transform.position + PlacePositionRelative; //transform.SetParent(itemHolding.transform); if (currentContainer.transform.childCount > 0) { //move item inside container to new container InteractableBase child = currentContainer.transform.GetChild(0).gameObject.GetComponent <InteractableBase>(); Debug.Log("3: " + child); child.transform.position = transform.position; child.transform.SetParent(transform); //objects in containers should not be selectable until taken out of the container currentContainer.GetComponent <SelectableObject>().enabled = false; //add the empty into to interaction to the list interactableComponent.AddInteractionToList("Empty into", EmptyInto); } }
void CheckForInteractable() { Ray _ray = new Ray(m_cam.transform.position, m_cam.transform.forward); RaycastHit _hitInfo; bool _hitSomething = Physics.SphereCast(_ray, raySphereRadius, out _hitInfo, rayDistance, interactableLayer); if (_hitSomething) { InteractableBase _interactable = _hitInfo.transform.GetComponent <InteractableBase>(); if (_interactable != null) { if (interactionData.IsEmpty()) { interactionData.Interactable = _interactable; uiPanel.SetTooltip(_interactable.TooltipMessage); } else { if (!interactionData.IsSameInteractable(_interactable)) { interactionData.Interactable = _interactable; uiPanel.SetTooltip(_interactable.TooltipMessage); } } } } else { uiPanel.ResetUI(); interactionData.ResetData(); } Debug.DrawRay(_ray.origin, _ray.direction * rayDistance, _hitSomething ? Color.green : Color.red); }
public void SetInteractable(InteractableBase newInteractable) { interactable = newInteractable; }
void CheckCharacterMovementInput() { CharacterAction nextAction = CharacterAction.NoAction; bool interacting = false; if (stunned) { nextAction = CharacterAction.Wait; } else if (confused) { nextAction = m_Input.GetRandomAction(); } else { nextAction = m_Input.CheckMovementInput(); interacting = m_Input.CheckInteractionInput(); } switch (nextAction) { case CharacterAction.MoveForward: m_MovementController.Move(transform.forward); break; case CharacterAction.Backstep: m_MovementController.Move(transform.forward * -1); break; case CharacterAction.MoveLeft: m_MovementController.Move(transform.right * -1); break; case CharacterAction.MoveRight: m_MovementController.Move(transform.right); break; case CharacterAction.TurnLeft: m_MovementController.Turn(-1); break; case CharacterAction.TurnRight: m_MovementController.Turn(1); break; case CharacterAction.Wait: SwitchCharacterStatus(CharacterStatus.idle); ActivationIsDone(); break; } if (interacting) { TileBase tile = m_MovementController.CheckTile(transform.forward); InteractableBase interactable = tile.GetComponentInChildren <InteractableBase>(); if (interactable != null) { interactable.InteractedWith(); SwitchCharacterStatus(CharacterStatus.idle); if (DungeonBaseController.instance.currentDungeonTurnState != DungeonBaseController.dungeonTurnState.SettingUpDungeon) { ActivationIsDone(); } } } if (nextAction != CharacterAction.NoAction) { LastAction = nextAction; } }
void Start() { //get the interactable component and add interactions to it interactableComponent = GetComponent <InteractableBase>(); interactableComponent.AddInteractionToList("Place On Burner", PlacedOnBurner); }
void Start() { //get the interactable component and add interactions to it interactableComponent = GetComponent <InteractableBase>(); interactableComponent.AddInteractionToList("Fill With Water", FillWithWater); }
public void SetFocus(InteractableBase newFocus) { focus = newFocus; }
public void onTriggerEnter(InteractableBase collidingItem) { collidingObjects.Add(collidingItem); }
private void Awake() { m_interactableBase = null; m_attackable = GetComponentInChildren <Attackable>(); m_movementModel = GetComponent <CharacterMovementModel>(); }
public void SetInteractableBase(InteractableBase interactableBase) { m_interactableBase = interactableBase; }
private void Start() { //initialize all of the interactions and triggers interactableComponent = GetComponent <InteractableBase>(); interactableComponent.AddInteractionToList("Place Spatula", HoldItem); }
public void onTriggerExit(InteractableBase collidingItem) { collidingObjects.Remove(collidingItem); }
// OnStateExit is called when a transition ends and the state machine finishes evaluating this state override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { InteractableBase interactable = targetGameObject.GetComponent <InteractableBase>(); interactable.OnInteract(); }