/////////////////////////////////////////////////////////////////////////// public void UpdateHighlightedObject() { GameObject newHighlightObject = null; Vector2 selfPos = transform.position.xz(); Vector2 lookDir = transform.forward.xz(); lookDir.Normalize(); Trap nearestTrap = TrapManager.Get().GetNearestTrap(true, EquippedTool, selfPos, true, true, lookDir); if (nearestTrap) { newHighlightObject = nearestTrap.gameObject; } else { Tool nearestTool = ToolTrolley.Get().GetNearestTool(selfPos, true, lookDir); if (nearestTool) { newHighlightObject = nearestTool.gameObject; } } if (newHighlightObject != HighlightedObject) { if (HighlightedObjectIcon) { GameObject.Destroy(HighlightedObjectIcon); } if (newHighlightObject) { // highlight new HighlightedObjectIcon = WorldSpaceCanvas.Get().CreateInteractIcon(GetPlayerColor(Slot)); } HighlightedObject = newHighlightObject; } if (HighlightedObject && HighlightedObjectIcon) { if (!EquippedTool || HighlightedObject != EquippedTool.gameObject) { float offset = HighlightedObject.gameObject.GetComponent <Tool>() ? 0.8f : 2.0f; HighlightedObjectIcon.transform.position = HighlightedObject.transform.position + Vector3.up * offset; Vector3 offsetTowardsCamera = (Camera.main.transform.position - HighlightedObject.transform.position); offsetTowardsCamera.Normalize(); HighlightedObjectIcon.transform.position += offsetTowardsCamera * 2.0f; } } }
/////////////////////////////////////////////////////////////////////////// void SetStuckParticlesEnabled(bool enable) { if (stuckPS) { if (enable) { stuckPS.Play(); } else { stuckPS.Stop(); } } else { WorldSpaceCanvas.Get().AddText("I'm Angry!", transform.position); } }
/////////////////////////////////////////////////////////////////////////// void TryInteraction() { bool doInteract = Input.GetButtonDown(GetInputPrefix() + "Interact"); if (doInteract) { CharAnim.SetTrigger("Work"); Vector2 selfPos = transform.position.xz(); Vector2 selfLookDir = transform.forward.xz(); selfLookDir.Normalize(); // 1) Traps if (EquippedTool && EquippedTool._ToolType != ToolType.Megaphone) { Trap nearestTrap = TrapManager.Get().GetNearestTrap(true, EquippedTool, selfPos, true, true, selfLookDir); if (nearestTrap) { if (EquippedTool) { AudioManager.Get().PlayRandomOneShot(gameObject, EquippedTool.RepairSound, EquippedTool.RepairSoundVolume); } nearestTrap.Interact(); return; } if (TrapManager.Get().GetNearestTrap(false, EquippedTool, selfPos, true, true, selfLookDir)) { PlayFailSound(); WorldSpaceCanvas.Get().AddText("Wrong Tool", transform.position); return; } } // 2) Trolley Tool nearestTool = ToolTrolley.Get().GetNearestTool(selfPos, true, selfLookDir); if (nearestTool) { ToolTrolley.Get().SwitchTool(ref EquippedTool, nearestTool); if (EquippedTool._ToolType == ToolType.Drill) { ToolVisuals[0].gameObject.SetActive(true); ToolVisuals[1].gameObject.SetActive(false); ToolVisuals[2].gameObject.SetActive(false); ToolVisuals[3].gameObject.SetActive(false); } else if (EquippedTool._ToolType == ToolType.Hammer) { ToolVisuals[0].gameObject.SetActive(false); ToolVisuals[1].gameObject.SetActive(true); ToolVisuals[2].gameObject.SetActive(false); ToolVisuals[3].gameObject.SetActive(false); } else if (EquippedTool._ToolType == ToolType.Megaphone) { ToolVisuals[0].gameObject.SetActive(false); ToolVisuals[1].gameObject.SetActive(false); ToolVisuals[2].gameObject.SetActive(true); ToolVisuals[3].gameObject.SetActive(false); } else if (EquippedTool._ToolType == ToolType.Mop) { ToolVisuals[0].gameObject.SetActive(false); ToolVisuals[1].gameObject.SetActive(false); ToolVisuals[2].gameObject.SetActive(false); ToolVisuals[3].gameObject.SetActive(true); } return; } // 3) Megaphone if (EquippedTool && EquippedTool._ToolType == ToolType.Megaphone) { if (Time.time - m_LastMegaphoneUsage > MegaphoneCooldown) { AudioManager.Get().PlayRandomOneShot(EquippedTool.gameObject, EquippedTool.RepairSound, EquippedTool.RepairSoundVolume); m_LastMegaphoneUsage = Time.time; Vector2 ownPos = transform.position.xz(); Vector2 ownForward = transform.forward.xz(); Vector2 MegaphoneImpactCenter = ownPos + ownForward * MegaphoneImpactDistance; List <Walker> walkers = WalkerManager.Get().GetAllWalkers(Vector2.zero, null); foreach (Walker walker in walkers) { Vector2 walkerPos = walker.transform.position.xz(); float dist = Vector2.Distance(walkerPos, MegaphoneImpactCenter); float impactAmount = 1.0f - Mathf.InverseLerp(MegaphoneInnerRadius, MegaphoneOuterRadius, dist); impactAmount = Mathf.Clamp01(impactAmount); if (impactAmount <= 0.0f) { continue; } float debugHeight = transform.position.y + 0.1f; Debug.DrawLine(MegaphoneImpactCenter.To3D(debugHeight), walkerPos.To3D(debugHeight)); Vector2 pushDir = (walkerPos - MegaphoneImpactCenter).normalized; /* * Vector2 orthogonalVector = new Vector2(ownForward.y, -ownForward.x); * * if (Vector2.Dot(orthogonalVector, pushDir) < 0.0f) * { * orthogonalVector *= -1.0f; * } * * pushDir = Vector2.Lerp(pushDir, orthogonalVector, MegaphoneOrthogonalPush).normalized; */ Debug.DrawLine(walkerPos.To3D(debugHeight), (walkerPos + pushDir * 3.0f).To3D(debugHeight), Color.red); walker.MegaphoneForceAmountNorm = impactAmount; walker.MegaphoneForceDirection = pushDir.normalized; walker.Reorient(); } } return; } // 4) Error PlayFailSound(); } }