void OnCollisionEnter(Collision other) { //MeshCollider newCollider = other.gameObject.GetComponent<MeshCollider>(); Projectile newProjectile = other.gameObject.GetComponent <Projectile>(); if (!newProjectile) { GameObject newExplosion = Instantiate(explosionPrefab, transform.position, transform.rotation) as GameObject; PhysicsExplosion explosionComponent = newExplosion.GetComponent <PhysicsExplosion>(); explosionComponent.Initialize(this.controller); Destroy(this.gameObject); } }
// Update is called once per frame void Update() { currentNumUnits = myAgents.Count; UpdateText(); if (Input.GetKeyDown(KeyCode.N)) { SpawnMultiUnits(); } if (!gameOver) { spawnRateCounter++; if (spawnRateCounter >= spawnRate) { spawnRateCounter = 0; SpawnMultiUnits(); } } if (Input.GetKeyDown(KeyCode.Escape)) { Application.LoadLevel(0); } if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { Rigidbody newRB = hit.collider.gameObject.GetComponent <Rigidbody>(); RigidbodyControl rBC = hit.collider.gameObject.GetComponent <RigidbodyControl>(); if (newRB) { newRB.AddForceAtPosition(-hit.normal * 250, hit.point); } if (rBC) { if (connectionGrid.DisableNode(hit.collider.gameObject.transform.position)) { rBC.ActivateRigidbody(); } } } } if (Input.GetMouseButtonDown(1)) { GameObject newExplosion = Instantiate(physicsExplosionPrefab, player.transform.position, Quaternion.identity) as GameObject; PhysicsExplosion newPExplosion = newExplosion.GetComponent <PhysicsExplosion>(); newPExplosion.Initialize(connectionGrid); } }