/// <summary> /// Player interacts with grenade materials and increments count /// </summary> /// <param name="collision"></param> private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag == "Grenade Material") { //This should probably be an event instead if (gameObject.GetComponent <ToolBelt>().allToolsDisabled == true) { //AudioManager.Instance.Play(AudioClipName.stasis_Grenade_TTS); gameObject.GetComponent <ToolBelt>().enabledTool = Constants.Tools.StasisGrenade; gameObject.GetComponent <ToolBelt>().allToolsDisabled = false; //invoke event to change highlight to grenade selectionChangeEvent.Invoke(Constants.Tools.StasisGrenade); } Destroy(collision.gameObject); grenadeCount++; //TEMPORARY CODE FOR TUTORIAL TO TESTERS if (grenadeCount > 5) { grenadeCount = 5; } //update the count in the UI for the stasis grenade updateCountEvent.Invoke(Constants.Tools.StasisGrenade, grenadeCount); AudioManager.Instance.Play(AudioClipName.item_Pickup); } }
/// <summary> /// Used to detect tripwire material pick ups as this is attached to the player /// </summary> /// <param name="collision"></param> private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag == "Trip Wire Materials") { //this should probably be an event instead if (gameObject.GetComponent <ToolBelt>().allToolsDisabled == true) { // AudioManager.Instance.Play(AudioClipName.tripwire_TTS); gameObject.GetComponent <ToolBelt>().enabledTool = Constants.Tools.TripWire; gameObject.GetComponent <ToolBelt>().allToolsDisabled = false; //invoke the event to change the UI to make the tripwire the enabled tool changeSelectionEvent.Invoke(Constants.Tools.TripWire); } tripWireCount++; //TEMPORARY CODE FOR TUTORIAL TO TESTERS if (tripWireCount > 5) { tripWireCount = 5; } updateCountEvent.Invoke(Constants.Tools.TripWire, tripWireCount); Destroy(collision.gameObject); AudioManager.Instance.Play(AudioClipName.item_Pickup); } }
// Update is called once per frame void FixedUpdate() { Physics2D.IgnoreCollision(gameObject.GetComponent <Collider2D>(), playerForPosition.GetComponent <Collider2D>()); if (Input.GetKeyUp(KeyCode.Mouse1) && !pinging) { //Debug.Log("Pinging"); gameObject.transform.position = playerForPosition.transform.position; AudioManager.Instance.Play(AudioClipName.transponder_RadarBleeps); playerForPosition.GetComponent <PingDevice>().pingDeviceCount--; //invoke event to update count for UI updateCountEvent.Invoke(Constants.Tools.PingDevice, playerForPosition.GetComponent <PingDevice>().pingDeviceCount); if (playerForPosition.GetComponent <PingDevice>().pingDeviceCount <= 0) { playerForPosition.GetComponent <ToolBelt>().disableTool(Constants.Tools.PingDevice); } pinging = true; } if (pinging) { if (!setStartOfPing) { render.sprite = radarRingPing; scale.localScale = new Vector3(startScale, startScale, 1); setStartOfPing = true; } if (scale.localScale.x < 1.7) { scale.localScale += new Vector3(scaleRate, scaleRate, 0); } else { render.color -= new Color(0, 0, 0, fadeRate); if (render.color.a < 0.01) { //Debug.Log("Disable here??"); scale.localScale = new Vector3(startScale, startScale, 0); render.color += new Color(0, 0, 0, 1); Destroy(gameObject); } } } else if (!pinging) { gameObject.transform.position = playerForPosition.transform.position; } }
/// <summary> /// Used to check for player input to place the tripwire fully /// </summary> void Update () { //trip wire is looking for input from player to place down second part of wire every frame //if the wire is placed, the trip wire should no longer care about player input //there's no way to set fullTrapSet back to false for this instance once its set to true //therefore once this instance of the tripwire is placed, it cant be placed again // grabs the vector position of the mouse cursor Vector3 cursorPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); // creates a new direction value by using the coordinate differences between the cursor and player Vector3 direction = (new Vector3(cursorPosition.x - player.transform.position.x, cursorPosition.y - player.transform.position.y, 0).normalized); // Also assuming that a unit square in Unity is 128x128 float spriteWidth = player.GetComponent<SpriteRenderer>().sprite.rect.width / 128; //waiting for the key Q to be lifted up to place the wire completely if (Input.GetKeyUp(KeyCode.Mouse1) && !fullTrapSet) { //play sound for placing trap AudioManager.Instance.Play(AudioClipName.tripWire_Placement1); //instantiates the final trip wire piece in front of the player finalPlacementTripWire = Instantiate(finalPlacementTripWire, player.transform.position + direction * .85f, player.transform.rotation); Physics2D.IgnoreCollision(player.GetComponent<Collider2D>(), finalPlacementTripWire.GetComponent<Collider2D>()); //decreasing one material from players inventory player.GetComponent<TripWire>().tripWireCount--; //invoke event updateCountEvent.Invoke(Constants.Tools.TripWire, player.GetComponent<TripWire>().tripWireCount); if (player.GetComponent<TripWire>().tripWireCount <= 0) { player.GetComponent<ToolBelt>().disableTool(Constants.Tools.TripWire); } //this way this instance of the trap cant be set anymore to a new position //and trap can start casting rays to look for an enemy fullTrapSet = true; //this way player can place another initial plug player.GetComponent<TripWire>().initialTripWirePlaced = false; } }
private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag == "Ping Materials") { if (gameObject.GetComponent <ToolBelt>().allToolsDisabled == true) { // AudioManager.Instance.Play(AudioClipName.tripwire_TTS); gameObject.GetComponent <ToolBelt>().enabledTool = Constants.Tools.PingDevice; gameObject.GetComponent <ToolBelt>().allToolsDisabled = false; //invoke the event to change the UI to make the tripwire the enabled tool changeSelectionEvent.Invoke(Constants.Tools.PingDevice); } AudioManager.Instance.Play(AudioClipName.item_Pickup); pingDeviceCount += 2; //TEMPORARY CODE FOR TUTORIAL TO TESTERS if (pingDeviceCount > 5) { pingDeviceCount = 5; } updateCountEvent.Invoke(Constants.Tools.PingDevice, pingDeviceCount); Destroy(collision.gameObject); } }