Quantcast
Channel: Questions in topic: "javascipt"
Viewing all articles
Browse latest Browse all 1875

bullet destroy on collison

$
0
0
after adding in the 'Destroy(gameObject);' line to destroy the bullet after colliding with a wall for example the enemy will not shoot. Any ideas as to why? bullet script: var Dammage = 50; function OnCollisionEnter (info : Collision) { info.transform.SendMessage("ApplyDammage1", Dammage, SendMessageOptions.DontRequireReceiver); Destroy(gameObject); } function Update () { var translation : float = Time.deltaTime * 60; transform.Translate(0,0,translation); } ai script: var Distance; var Target : Transform; var ShootRange = 25.0; var attackRange = 15.0; var moveSpeed = 5.0; var Damping = 6.0; var projectile : Rigidbody; var fireRate : float = 1; var FireRange = 0-100; private var nextFire : float = 0.0; function Update () { Distance = Vector3.Distance(Target.position, transform.position); if (Distance < ShootRange) { GetComponent.().material.color = Color.yellow; lookAt(); } if (Distance > ShootRange) { lookAt(); } if (Distance < attackRange) { GetComponent.().material.color = Color.red; attack (); } if (Distance > attackRange && Time.time > nextFire ) { nextFire = Time.time + fireRate; Instantiate(projectile, transform.position, transform.rotation); } } function lookAt () { var rotation = Quaternion.LookRotation(Target.position - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * Damping); } function attack () { transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime); }

Viewing all articles
Browse latest Browse all 1875

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>