Quantcast
Channel: Questions in topic: "invokerepeating"
Viewing all articles
Browse latest Browse all 220

Can I increase gravity / fallspeed of instantiated prefabs over time?

$
0
0
Hello! I am working on a 2D color matching / catch game and I am trying to increase the gravity of my instantiated objects so the longer the game goes on, the faster they fall. Here is the code I am using to instantiate my prfabs: using UnityEngine; using System.Collections; public class SpawnBox : MonoBehaviour { public GameObject[] boxList; private bool gameOver; public GameObject gameOverText; public GameObject restartButton; public GameObject menuButton; void Start() { gameOver = false; StartCoroutine(SpawnNewBox()); } IEnumerator SpawnNewBox() { yield return new WaitForSeconds (1.75f); while (!gameOver) { int i = Random.Range (0, boxList.Length); Instantiate (boxList [i], transform.position, Quaternion.identity); yield return new WaitForSeconds (Random.Range (2.0f, 3.1f)); } GameObject.FindGameObjectWithTag("MainCamera").GetComponent().Stop(); GameObject.FindGameObjectWithTag("Destroyer").GetComponent().Play(); gameOverText.SetActive(true); yield return new WaitForSeconds (1.5f); restartButton.SetActive(true); menuButton.SetActive(true); } public void GameOver() { gameOver = true; } } I have tried using InvokeRepeating and AddForce in the start function and in an update function but with no luck. Any assistance / guidance is greatly appreciated!!

Viewing all articles
Browse latest Browse all 220

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>