void OnTriggerEnter2D(Collider2D other) { if (!other.isTrigger && other.gameObject.tag != "Car") { currentCar = other.gameObject.transform.parent.GetComponent <CarBotScript>(); if (currentCar.pathing.Count == 0) { currentCar.updatePath(); } char currentDirection = currentCar.pathing[0]; currentCar.setDirection(currentDirection); currentCar.pathing.Remove(currentDirection); } }
private void OnTriggerEnter2D(Collider2D other) { if (!other.isTrigger && other.gameObject.tag == "Car") { currentCar = other.gameObject.GetComponent <CarBotScript>(); if (currentCar.isInScene()) { Destroy(other.gameObject); } else { currentCar.setInScene(true); } } }
// private void OnCollisionEnter2D(Collision2D other) // { // if (other.gameObject.tag == "Car" || other.gameObject.tag == "Accident") // { // canMove = false; // gameObject.tag = "Accident"; // other.gameObject.tag = "Accident"; // Destroy(gameObject, timeToDie); // } // } private void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == "Accident") { otherCar = FindObjectOfType <CarBotScript>(); canMove = false; Invoke("enableMove", otherCar.timeToDie); } else if (other.gameObject.tag == "Car") { canMove = false; } else { current_traffic_light = other.gameObject.GetComponent <TrafficController>(); } }
// Update is called once per frame void Update() { spawnTimer -= Time.deltaTime; if (spawnTimer <= 0.0f) { if (StageManager.carsLeft < StageManager.carLimit && startSpawn <= StageManager.carsCount && StageManager.carsCount < stopSpawn) { GameObject obj = (GameObject)Instantiate(prefab, transform.position, Quaternion.identity); currentCar = obj.GetComponent <CarBotScript>(); currentCar.direction = carDirection; int size = command.Count; for (int i = 0; i < size; i++) { currentCar.command.Add(command[i]); } StageManager.carsCount += 1; ResetSpawnTimer(); } } }