void OnCollisionEnter2D(Collision2D collision) { ContactPoint2D contact = collision.contacts[0]; FallingSite other = contact.collider.gameObject.GetComponent <FallingSite>(); if (other != null) { if (hasBeenOnScreen && other.hasBeenOnScreen) { collector.OnCollisionEnter2D(collision); } /* * collector.nextSlot.y += 1.5f; * other.transform.parent = collector.transform; * this.rigidbody2D.isKinematic = true; * this.rigidbody2D.isKinematic = true; * Vector2 oldPositon = new Vector2(other.transform.position.x, other.transform.position.y); * Vector2 newPosition = collector.nextSlot; * other.transform.position = Vector2.Lerp(oldPositon, newPosition, 0.5f); * //site.transform.rigidbody2D.Sleep(); * /* Need to also update the collider on this object to include the bounds of * the recently caught site */ } }
public void decodeTXT(string filename) { StreamReader stream = new StreamReader(filename); string line; int count = 0; while ((line = stream.ReadLine()) != null) { if (count > MAX_ENTRIES) { break; } if (line.Contains("URL")) { string[] split = Regex.Split(line, " : "); if (split.Length > 1) { line = split[1]; line = line.Trim(); if (!line.Contains("http")) { continue; } GameObject prefab; int random = Random.Range(0, 100); if (random < 30) { prefab = (GameObject)Instantiate(Resources.Load("RedDroid")); } else if (random < 60) { prefab = (GameObject)Instantiate(Resources.Load("YellowDroid")); } else { prefab = (GameObject)Instantiate(Resources.Load("FallingSitePrefab")); } FallingSite toAdd = prefab.GetComponent <FallingSite>(); toAdd.siteURL = line; toAdd.value = random; prefab.rigidbody2D.isKinematic = true; prefab.rigidbody2D.gravityScale = 0.0f; prefab.transform.position = new Vector2(0, 30); toAdd.collector = collector; downloadedSites.Add(toAdd); count++; } } } stream.Close(); }
public void OnCollisionEnter2D(Collision2D collision) { ContactPoint2D contact = collision.contacts[0]; FallingSite site = contact.collider.gameObject.GetComponent <FallingSite>(); if (site != null) { Debug.Log("Hit the collector"); site.GetComponent <BoxCollider2D>().enabled = false; site.rigidbody2D.isKinematic = true; site.transform.parent = this.transform; Debug.Log("NEXT SLOT: " + nextSlot); site.transform.localPosition = nextSlot; nextSlot.y += 3.8f; this.addSite(site); this.GetComponent <BoxCollider2D>().size += new Vector2(0f, 7.4f); if (sites.Count > 6) { camera.transform.position += new Vector3(0, 1.5f, 0f); } foreach (FallingSite obj in data.downloadedSites) { if (!obj.dropped && obj.transform.parent == null) { Vector2 oldPos = obj.transform.position; obj.transform.position = new Vector3(oldPos.x, oldPos.y + 1.5f); } } //site.transform.rigidbody2D.Sleep(); /* Need to also update the collider on this object to include the bounds of * the recently caught site */ } else if (contact.collider.gameObject.name.Equals("rightWall")) { onRightWall = true; } else if (contact.collider.gameObject.name.Equals("leftWall")) { onLeftWall = true; } }
void addSite(FallingSite site) { sites.Push(site); numSites++; value += site.value; }