//Collision mgmt private void OnCollisionEnter2D(Collision2D collision) { if (collision.collider.CompareTag("Meat")) { Debug.Log("DINO COLLISION!!!!"); MeatMovement dm = collision.gameObject.GetComponent <MeatMovement>(); int points = dm.GetValue(); //use this to update corresponding score in scoremanager score.AddPoints(playerid, points); //update score in score manager Destroy(collision.gameObject); } }
//spawns meat; call in update void Spawn() { //if this is not active, skip spawning if (!active) { return; } //update spawn timer spawntimer -= Time.deltaTime; //if timer <= 0 reset timer if (spawntimer <= 0) { //if the max number of meats hasn't been reached, spawn meat if (numspawned < maxnum) { if (debug) { Debug.Log(TAG + ": spawning meat"); } GameObject spawnee = Instantiate(meatfab); spawnee.transform.position = new Vector2(Random.Range(minx, maxx), spawny); MeatMovement mm = spawnee.GetComponent <MeatMovement>(); int index = Random.Range(0, spawnarray.Count - 1); if (debug) { Debug.Log(TAG + ": spawning meat #" + index + ". Name = " + meatlist.list[spawnarray[index]]); } mm.SetMeatData(meatlist.list[spawnarray[index]]); mm.spawner = this; //not best practice to directly access this field, but whatever. This gives the MeatMovement script a reference to this script, so that the MeatMovement script will subtract 1 from this script's meat counter upon the meat's destruction. mm.SetScoreManager(mgmt.GetComponent <ScoreManager>()); numspawned++; } spawntimer = Random.Range(mintime, maxtime); } }