void OnTriggerEnter2D(Collider2D collision) { string val = collision.tag; //Debug.Log("Collided with "+val+"!"); if (val == "Pair") { //check if pair matches an element in the list TrackPair pair = collision.GetComponent <TrackPair>(); if (pair.Damaged) { for (int i = 0; i < GrabbedStuff.Count; i++) { if (GrabbedStuff[i].PairType == pair.ActiveType) { pair.Repair(); Source.PlayOneShot(DropOffSounds[Random.Range(0, DropOffSounds.Length)]); Display.Remove(GrabbedStuff[i].GetComponent <SpriteRenderer>().sprite); Spawner.ActivateSpawner(); Spawner.StopTracking(GrabbedStuff[i].transform); Destroy(GrabbedStuff[i].gameObject); GrabbedStuff.RemoveAt(i); ScoreManager.AddToScore(FixPairValue); break; } } } //if(pair.Damaged && GrabbedStuff.Count>0){ // pair.Repair(); // Spawner.ActivateSpawner(); // Spawner.StopTracking(GrabbedStuff[0].transform); // Destroy(GrabbedStuff[0].gameObject); // GrabbedStuff.RemoveAt(0); // ScoreManager.AddToScore(FixPairValue); //} } else if (val == "Grabbable") { Source.PlayOneShot(PickUpSounds[Random.Range(0, PickUpSounds.Length)]); collision.transform.SetParent(transform); GrabbedStuff.Add(collision.GetComponent <Grabbable>()); collision.GetComponent <SpaceObject>().Stop(); ScoreManager.AddToScore(PickUpValue); Display.PickUp(collision.GetComponent <SpriteRenderer>().sprite); //if On Add to list //otherwise don't } else if (val == "Rock") { //Shatter? } }
private void OnTriggerEnter2D(Collider2D collision) { if (dead) { return; } string val = collision.tag; if (val == "Pair") { //if complete live //else take damage and maybe die TrackPair pair = collision.GetComponent <TrackPair>(); if (pair.Damaged) { Rb.velocity = Tools.RandomDirection(Rb.velocity, 10.0f, 100.0f); //float angle = Mathf.Deg2Rad * (Random.Range(10.0f, 100.0f) * (Random.Range(0, 2) == 0 ? 1 : -1)); //Rb.velocity = new Vector2(Mathf.Cos(angle) * Rb.velocity.x - Mathf.Sin(angle) * Rb.velocity.y, //Mathf.Sin(angle) * Rb.velocity.x + Mathf.Cos(angle) * Rb.velocity.y); Rb.velocity *= 0.75f; pair.Repair(false); Source.PlayOneShot(SkipSounds[Random.Range(0, SkipSounds.Length)]); Player.LoseTrain(); Die(); } else { if (pair.Fixed) { Player.AddToScore(TravelledPairValue); } } } else if (val == "Link") { //Get new destinaiton collision.GetComponent <TrainLink>().SetNextDirection(this); } }