private void OnCollisionEnter(Collision collision) { if (collitionActive) { ContactPoint hit = collision.contacts[0]; ExplosiveController.addExplotion(hit.point, explotionForce, explotionRadius, damage, layer); if (!collision.transform.root.tag.Contains("Player")) { GameObject dec = Instantiate(decal, hit.point + (hit.normal * CarSetup.minSurfaceDistance), Quaternion.LookRotation(hit.normal), collision.transform); dec.AddComponent <LifeTime>().lifeTime = CarSetup.globalLifetime; dec.SetActive(true); } Destroy(gameObject); } }
// Use this for initialization void Start() { layer = gameObject.layer; Setup = GetComponent <CarSetup>(); material = Setup.intenceRed; minePrefab = new GameObject("mine"); minePrefab.SetActive(false); mineDecal = new GameObject("mineDecal"); mineDecal.SetActive(false); mineDecal = Resources.Load <GameObject>("explotionDecal"); GameObject mineObject = Resources.Load <GameObject>("mine"); CarSetup.initMesh(minePrefab, mineObject.transform.Find("mine_mesh").GetComponent <MeshFilter>().sharedMesh, material); MeshCollider sensor = minePrefab.AddComponent <MeshCollider>(); sensor.sharedMesh = mineObject.transform.Find("mine_sensor").GetComponent <MeshFilter>().sharedMesh; sensor.convex = true; sensor.isTrigger = true; MeshCollider collider = minePrefab.AddComponent <MeshCollider>(); collider.sharedMesh = mineObject.transform.Find("mine_collider").GetComponent <MeshFilter>().sharedMesh; collider.convex = true; Rigidbody rb = minePrefab.AddComponent <Rigidbody>(); rb.mass = 5; rb.collisionDetectionMode = CollisionDetectionMode.Continuous; minePrefab.layer = layer; ExplosiveController explosive = minePrefab.AddComponent <ExplosiveController>(); explosive.useSensor = true; explosive.damage = explotionDamage; explosive.layer = layer; explosive.explotionForce = explotionForce; explosive.explotionRadius = explotionRadius; explosive.decal = mineDecal; }