Shooting update

I updated the player shooting script to destroy enemies on click. This is currently the most effective form of shooting so we’ll stick with this for now and try to improve it later on aesthetically.

e7b8aad87c

Enemy being destroyed

It works by creating a bullet inside the enemy at its current location, instantly destroying it. I was able to do this by modifying my previous shooting code, and adding this to it:

if (Physics.Raycast(ray, out hit) && Input.GetMouseButtonDown(0))
			{
				Debug.Log (hit.collider.gameObject);
				enemy = hit.collider.gameObject;
				Invoke("Fire",fireTime);	
				Rigidbody newBullet = Instantiate(bullet,transform.position,transform.rotation) as Rigidbody;
				newBullet.AddForce(transform.forward*velocity,ForceMode.VelocityChange);
				newBullet.transform.position = Vector3.Lerp(newBullet.transform.position, enemy.transform.position, velocity);	//destroy enemy on click

			}

Leave a comment