Пример #1
0
        /// <summary>
        /// Setup <see cref="MapsService"/>. Give buildings mesh colliders and make them explodeable.
        /// </summary>
        private void MapsServiceSetup()
        {
            MapsService = GetComponent <MapsService>();
            MapsService.Events.ExtrudedStructureEvents.DidCreate.AddListener(args => {
                // Assign every building a mesh collider, so player and bullets can collide with them.
                MeshFilter meshFilter = args.GameObject.GetComponent <MeshFilter>();
                MeshCollider collider = args.GameObject.AddComponent <MeshCollider>();

                collider.sharedMesh = meshFilter.sharedMesh;

                // Assign every building a building exploder.
                BuildingExploder exploder = args.GameObject.AddComponent <BuildingExploder>();
                exploder.ChunkMaterial    = BuildingChunkMaterial;
            });
        }
Пример #2
0
        /// <summary>
        /// Explode when the missile collides with something.
        /// </summary>
        /// <param name="hit">Information about the collision.</param>
        private void OnControllerColliderHit(ControllerColliderHit hit)
        {
            GameObject explosion = Instantiate(ExplosionPrefab);

            explosion.transform.position = gameObject.transform.position;

            BuildingExploder exploder = hit.gameObject.GetComponent <BuildingExploder>();

            if (exploder != null)
            {
                exploder.Explode(gameObject.transform.position);
            }

            Destroy(gameObject);
        }