// Update is called once per frame void Update() { //Translate the projectile in the up direction cause bullet travels on Y axis myTransform.Translate(Vector3.up * bulletSpeed * Time.deltaTime); // TODO: ADd particle effects here particleemitter.minSize = .1f; particleemitter.minSize = .4f; // if the ray hits something then execute this code. if (Physics.Raycast(myTransform.position, myTransform.up, out hit, range, layerMask) && alreadyhitsomething == false) { particleAnimator.force = particleForce; if (hit.transform.tag == "enemy1" && isbullet1) { /* // Dynamically create a fixedjoint to stick bullets to the enemy * var joint = myTransform.gameObject.AddComponent<FixedJoint>(); * joint.connectedBody = hit.transform.rigidbody; * projectileSpeed = 0; this fails. */ alreadyhitsomething = true; bulletSpeed = 0; // myTransform.collider.enabled = false; myTransform.collider.isTrigger = true; // myTransform.parent = hit.transform.gameObject.transform; myTransform.parent = hit.transform; // bacteria takes damage aibacteria = hit.collider.gameObject.GetComponent <AiBacteria>(); aibacteria.takeDamage(); // bacteria takes damage Debug.Log("enemy(bacteria) is hit"); } else if (hit.transform.tag == "enemy2" && isbullet2) { alreadyhitsomething = true; bulletSpeed = 0; myTransform.collider.isTrigger = true; myTransform.parent = hit.transform; // bacteria takes damage AiBacteria aibacteria = hit.collider.gameObject.GetComponent <AiBacteria>(); aibacteria.takeDamage(); // bacteria takes damage Debug.Log("enemy(bacteria) is hit"); if (aibacteria.alreadydead) { // particleemitter.minSize = .4f; // particleemitter.minSize = .8f; particleAnimator.force = new Vector3(0, 5, 0); Instantiate(bulletexplosion, hit.point, Quaternion.identity); } } else if (hit.transform.tag == "enemy4" && isbullet3) { alreadyhitsomething = true; bulletSpeed = 0; myTransform.collider.isTrigger = true; myTransform.parent = hit.transform; // bacteria takes damage AiBacteria aibacteria = hit.collider.gameObject.GetComponent <AiBacteria>(); aibacteria.takeDamage(); // bacteria takes damage Debug.Log("enemy(bacteria) is hit"); if (aibacteria.alreadydead) { // particleemitter.minSize = .4f; // particleemitter.minSize = .8f; particleAnimator.force = new Vector3(0, 5, 0); Instantiate(bulletexplosion, hit.point, Quaternion.identity); } } else { Instantiate(bulletexplosion, hit.point, Quaternion.identity); // TODO: Add particle effects here Destroy(myTransform.gameObject); } } }
// Update is called once per frame void Update() { //Translate the projectile in the up direction cause bullet travels on Y axis myTransform.Translate(Vector3.up * bulletSpeed * Time.deltaTime); // TODO: ADd particle effects here particleemitter.minSize = .1f; particleemitter.minSize = .4f; // if the ray hits something then execute this code. if (Physics.Raycast(myTransform.position, myTransform.up, out hit, range, layerMask) && alreadyhitsomething == false) { particleAnimator.force = particleForce; if (hit.transform.tag == "enemy1" && isbullet1) { /* // Dynamically create a fixedjoint to stick bullets to the enemy var joint = myTransform.gameObject.AddComponent<FixedJoint>(); joint.connectedBody = hit.transform.rigidbody; projectileSpeed = 0; this fails. */ alreadyhitsomething = true; bulletSpeed = 0; // myTransform.collider.enabled = false; myTransform.collider.isTrigger = true; // myTransform.parent = hit.transform.gameObject.transform; myTransform.parent = hit.transform; // bacteria takes damage aibacteria = hit.collider.gameObject.GetComponent<AiBacteria>(); aibacteria.takeDamage(); // bacteria takes damage Debug.Log("enemy(bacteria) is hit"); } else if (hit.transform.tag == "enemy2" && isbullet2) { alreadyhitsomething = true; bulletSpeed = 0; myTransform.collider.isTrigger = true; myTransform.parent = hit.transform; // bacteria takes damage AiBacteria aibacteria = hit.collider.gameObject.GetComponent<AiBacteria>(); aibacteria.takeDamage(); // bacteria takes damage Debug.Log("enemy(bacteria) is hit"); if (aibacteria.alreadydead) { // particleemitter.minSize = .4f; // particleemitter.minSize = .8f; particleAnimator.force = new Vector3(0, 5, 0); Instantiate(bulletexplosion, hit.point, Quaternion.identity); } } else if (hit.transform.tag == "enemy4" && isbullet3) { alreadyhitsomething = true; bulletSpeed = 0; myTransform.collider.isTrigger = true; myTransform.parent = hit.transform; // bacteria takes damage AiBacteria aibacteria = hit.collider.gameObject.GetComponent<AiBacteria>(); aibacteria.takeDamage(); // bacteria takes damage Debug.Log("enemy(bacteria) is hit"); if (aibacteria.alreadydead) { // particleemitter.minSize = .4f; // particleemitter.minSize = .8f; particleAnimator.force = new Vector3(0, 5, 0); Instantiate(bulletexplosion, hit.point, Quaternion.identity); } } else { Instantiate(bulletexplosion,hit.point, Quaternion.identity); // TODO: Add particle effects here Destroy(myTransform.gameObject); } } }