Been fighting this for a few days. I want the Coin to be collected with the player touches it. I thought I could copy my script from the other objects and just use it for the coins. So that is why it says pipe instead of coin. I just started coding 2 months ago so this could be a complete noob problem. MissingReferenceException: The object of type 'Transform' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object. UnityEngine.Transform.get_position () <0x34a0a450 + 0x0006a> in <c8d2deaeeb3a4471b3e224c2a136823a>:0 CoinSpawner.ShiftPipes () (at Assets/Scripts/CoinSpawner.cs:106) CoinSpawner.Update () (at Assets/Scripts/CoinSpawner.cs:81) Code (CSharp): void Update() { if (game.GameOver) return; targetAspect = (float)targetAspectRatio.x / targetAspectRatio.y; dynamicSpawnPos.x = (spawnPos.x * Camera.main.aspect) / targetAspect; spawnTimer += Time.deltaTime; if (spawnTimer >= spawnRate) { SpawnPipe(); spawnTimer = 0; } ShiftPipes(); } void SpawnPipe() { GameObject pipe = Instantiate(PipePrefab) as GameObject; pipe.transform.SetParent(transform); pipe.transform.localPosition = dynamicSpawnPos; if (beginInScreenCenter && pipes.Count == 0) { pipe.transform.localPosition = Vector3.zero; } float randomYPos = Random.Range(spawnHeight.min, spawnHeight.max); pipe.transform.position += Vector3.up * randomYPos; pipes.Add(pipe.transform); } void ShiftPipes() { for (int i = pipes.Count - 1; i >= 0; i--) { pipes[i].position -= Vector3.right * shiftSpeed * Time.deltaTime; if (pipes[i].position.x < (-dynamicSpawnPos.x * Camera.main.aspect) / targetAspect) { GameObject temp = pipes[i].gameObject; pipes.RemoveAt(i); Destroy(temp); } } }
Most likely you're adding items to `pipes' that are later getting destroyed by something else, yet you're continuing to access them here in your ShiftPipes method. If you're going to do this sort of thing, you should just make sure that pipes isn't null as you're looping over the pipes. Ideally remove entries that are null from time to time.
I fixed it just didn't update on here. I just destroy the sprite render and the collider. Might not be right but it works. Now I am on to new problems with google play services.
Code (CSharp): { private void OnTriggerEnter2D(Collider2D other) { { if (other.gameObject.tag == "Player") { GetComponent<SpriteRenderer>().enabled = false; GetComponent<Collider2D>().enabled = false; } } } }