- Home /
Unexpected token: targetPos
I get an error where my TOKEN is wrong, and I would really like too know what a token is :P. (Noob Here) So if you could help me that would be nice ^^
function (CalculateAimPosition targetPos = Vector3)
{
var aimPoint = Vector3(targetPos.x + aimError, targetPos.y + aimError, targetPos.z + aimError);
desiredRotation = Quaternion.LookRotation(aimPoint);
};
is targetPos a Transform type. When you declared targetPos what type did you give it. var targetPos : Transform;
Well, I added that, but it still dosen't work. Got any other ide? :S
Could you be more specific when you say "it does not work" ? Does it compile ? Do you have an error on runtime ?
Answer by KiraSensei · Nov 15, 2013 at 04:13 PM
Try :
function CalculateAimPosition (targetPos:Transform)
{
var aimPoint = Vector3(targetPos.x + aimError, targetPos.y + aimError, targetPos.z + aimError);
desiredRotation = Quaternion.LookRotation(aimPoint);
}
EDIT : here is the entire script :
var myProjectile : GameObject;
var reloadTime : float = 1f;
var turnSpeed : float = 5f;
var firePauseTime : float = .25f;
var muzzleEffect : GameObject;
var errorAmount : float = 0.01f;
var myTarget : Transform;
var turretBall: Transform;
var muzzlePositions : Transform;
var targetPos : Transform;
private var nextFireTime : float;
private var nextMoveTime : float;
private var desiredRotation : Quaternion;
private var aimError : float;
function Start () {
}
function Update () {
if(myTarget)
{
if(Time.time >= nextMoveTime)
{
CalculateAimPosition(myTarget.position);
turretBall.rotation = Quaternion.Lerp(turretBall.rotation.desiredRotation.time.deltaTime * turnSpeed);
}
if(Time.time >= nextFireTime)
{
FireProjectile();
}
}
}
function OnTriggerEnter (other : Collider) {
if (other.gameObject.tag == "Enemy")
{
nextFireTime = Time.time + (reloadTime * 0.5);
myTarget = other.gameObject.transform;
}
}
function OnTriggerExit (other : Collider){
if(other.gameObject.transform == myTarget)
{
myTarget = null;
}
}
function CalculateAimPosition (targetPos : Vector3) {
var aimPoint = Vector3(targetPos.x + aimError, targetPos.y + aimError, targetPos.z + aimError);
desiredRotation = Quaternion.LookRotation(aimPoint);
}
function CalculateAimError {
aimError = Random.Range(-errorAmount, errorAmount);
}
function FireProjectile {
audio.Play();
nextFireTime = Time.time + reloadTime;
nextMoveTime = Time.time + firePauseTime;
CalculateAimError();
for(theMuzzlePos in muzzlePositions)
{
Instantiate(myProjectile, theMuzzlePos.position, theMuzzlePos.rotation);
Instantiate(muzzleEffect, theMuzzlePos.position, theMuzzlePos.rotation);
}
}
Almost, $$anonymous$$iraSensei. Remove the ';' at the very end and that is the correct answer. If OP had been more informative with the errors, we would have had it by now.
Now if you have other errors, please tell exactly what they are and at what line.
50,9 unexpected token: myTarget
Life is hard time to time xdd :P
Why did you declare myTarget as a Transform[] ? It should be a Transform.
I reedited the code with others corrections
In a line you put :
myTarget : null;
This implies that you really don't know how to code. So you should stop trying like this and learn.