[FREE] Enemy Shooting Script and Walking!

Step 1: Add a “Character Controller” to your enemy object
Step 2: Add the “EnemyFollow.js” to the enemy and set it to whatever
Step 3: Create a empty GameObject at the very tip of your enemy’s gun, and assign “EnemyGun.js” to it
Step 4: Assign everything to everything, and voila!

EnemyFollow.js – enemyHeight is the enemy’s Y axis so that it dosen’t fly and stays at the axis

#pragma strict

var player : Transform;
var enemyHeight : float = 1.43;
var speed : int = 3;

function Start () {

}

function Update () {
	transform.LookAt(player);
	transform.position.y = enemyHeight;
	transform.position += transform.forward * speed * Time.deltaTime;
}

function OnTriggerEnter(col : Collider) {
	if(col.tag == "Bullet") {
		Destroy(gameObject);
	}
}

EnemyGun.js

var projectile : Rigidbody;
var speed = 10;
var player : Transform;
var shotS : AudioClip;

function Start() {
	var rendum = Random.Range(1F,3F);
	InvokeRepeating("Shuut", 2, rendum);
}

function Update() {
	transform.LookAt(player);
}

function Shuut () {
audio.PlayOneShot(shotS);
clone = Instantiate(projectile, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection( Vector3 (0, 0, speed));

Destroy (clone.gameObject, 0.5);
}

If you would want to give me credit in your game, thanks ^-^

NOTE! You can always put the enemy walk speed to static so you can change it after will through script by doing EnemyFollow.speed = 5 or something to change it :slight_smile:

how do you make the bullet shoot faster

Threads like this belong in the Assets section

@nerdgeek , Change the variable speed on EnemyGun.js

ok thank you so much i tried too find a enemy shooting script and you were the only one that had one

sorry about the questions am a nood at unity and i was wondering how you change the fire rate

thank you i’ve been looking for these scripts for my game for ages defo giving you some credit

it keeps saying this
Assets/EnemyGun.js(20,9): BCE0005: Unknown identifier: ‘clone’.
why is that?

This thread is 2.5 years old, eh…

yeah so

can you help

Post your code (maybe in a new thread) , the error and the line number (as it appears in the posted thread).
Use code tags, please :slight_smile: There is a pinned thread on how to do that, in the forums, if you don’t already know.