- Home /
Question by
BlackYukirin715 · Aug 17, 2014 at 03:46 PM ·
enemybullet
Enemy Shooting bullet
Well I am making a first person shooting game but it seems like that my enemy only shoots upwards when I set the rotation of the spawn point as zero as well as following programs from youtube channels (e.g. Tornadotwins) and it seems like that they don't work at all. Because I am a newbie towards unity I don't really know how it works so here below is my code and whats wrong with it?
var LookAtTarget:Transform; var damp = 1.0; var bullitPrefab:Transform; var savedTime=0; var enemyprojectile = Transform;
function Update ()
{
if(LookAtTarget)
{
var rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);
var seconds : int = Time.time;
var oddeven = (seconds / 2);
if (oddeven)
{
Shoot(seconds);
}
}
}
function Shoot(seconds)
{
if (seconds!=savedTime);
{
var bullit = Instantiate(bullitPrefab ,transform.Find("Spawn2").transform.position ,
Quaternion.identity);
bullit.gameObject.tag = "enemyprojectile";
bullit.rigidbody.AddForce(transform.forward * 1000);
savedTime=seconds;
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613160805im_/https://answers.unity.com/themes/thub/images/avi.jpg)