- Home /
Question by
thenachotech1113 · Jun 13, 2012 at 09:35 PM ·
shootrangeturretintellisenseartificial
turret shoot if in range
so i`m making a game were turrets have to shoot at you though they should shoot only of the they are in range but when i save the code it gives me 2 errors:
Operator '
Cannot convert 'float' to 'System.Type',
here is the code i used:
#pragma strict
function Start () {
}
var speed = 3000;
var distance = int;
var maxDistance = 50;
var myTransform = transform;
var LookAtTarget:Transform;
var bullitPrefab:Transform;
var damp = 6.0;
var savedTime = 0;
function Update ()
{
distance = (LookAtTarget.position - myTransform.position).magnitude;
if(LookAtTarget && distance < maxDistance)
{
var rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation,rotate,Time.deltaTime * damp);
var seconds : int = Time.time;
var evenodd = (seconds / 2);
if (evenodd)
{
Shoot(seconds);
}
}
}
function Shoot(seconds)
{
if(seconds!=savedTime)
{
var bullit = Instantiate(bullitPrefab,transform.Find("spawnPoint").transform.position,
Quaternion.identity);
bullit.rigidbody.AddForce(transform.forward * speed);
savedTime = (seconds);
}
}
so i hope someone can help me and thank you.
Comment
Best Answer
Answer by whydoidoit · Jun 13, 2012 at 10:24 PM
Your definition of distance is incorrect:
var distance : int;
You have an "=" in there which makes distance a variable containing the type of an int :)