// Update is called once per frame void Update() { if (Vector3.Distance(originalLocation, this.transform.position) > maxRange) { Destroy(this.gameObject); } if (Vector3.Distance(originalLocation, this.transform.position) > 50) { trailRenderer.enabled = true; } else { trailRenderer.enabled = false; } if (Vector3.Distance(originalLocation, this.transform.position) > damageRange) { damage = (int)(damage * damageDropoff); } Vector3 point1 = this.transform.position; float stepSize = 1.0f / predictionStepsPerFrame; for (float step = 0; step < 1; step += stepSize) { bulletVelocity += Physics.gravity * stepSize * Time.deltaTime; Vector3 point2 = point1 + bulletVelocity * stepSize * Time.deltaTime; Ray ray = new Ray(point1, point2 - point1); RaycastHit hitInfo; if (Physics.Raycast(ray, out hitInfo, (point2 - point1).magnitude)) { if (hitInfo.collider.tag == "Environment") { print(hitInfo.collider.material.name.Replace(" (Instance)", "")); Transform bullethole = Instantiate(bulletHolePrefabs[Random.Range(0, bulletHolePrefabs.Length)], hitInfo.point, Quaternion.LookRotation(hitInfo.normal)); bullethole.GetComponentInChildren <Renderer>().material = Resources.Load <Material>("Bulletholes/Materials/" + hitInfo.collider.material.name.Replace(" (Instance)", "")); } if (hitInfo.collider.gameObject.layer == 7) { Transform marker = Instantiate(Resources.Load <Transform>("Hitmarker"), GameObject.FindGameObjectWithTag("Center").transform.position, Resources.Load <Transform>("Hitmarker").rotation, GameObject.FindGameObjectWithTag("Canvas").transform); print(hitInfo.collider.material.name.Replace(" (Instance)", "")); PlayerManager _pm = hitInfo.collider.gameObject.GetComponent <PlayerManager>(); if (_pm.Damage(damage, damageMultiplier, hitInfo.collider.material.name.Replace(" (Instance)", "")) == true) { for (int i = 0; i < marker.GetComponentsInChildren <Image>().Length; i++) { marker.GetComponentsInChildren <Image>()[i].color = Color.red; } } } if (hitInfo.collider.gameObject.layer == 8) { Transform marker = Instantiate(Resources.Load <Transform>("Hitmarker"), GameObject.FindGameObjectWithTag("Center").transform.position, Resources.Load <Transform>("Hitmarker").rotation, GameObject.FindGameObjectWithTag("Canvas").transform); print(hitInfo.collider.material.name.Replace(" (Instance)", "")); ZombieManager _pm = hitInfo.collider.gameObject.GetComponent <ZombieManager>(); if (_pm.Damage(damage, damageMultiplier, hitInfo.collider.material.name.Replace(" (Instance)", "")) == true) { for (int i = 0; i < marker.GetComponentsInChildren <Image>().Length; i++) { marker.GetComponentsInChildren <Image>()[i].color = Color.red; } } } Destroy(this.gameObject); } point1 = point2; this.transform.position = point1; } }