- Home /
expecting (, found 'Update' and unexpected char: 0x200B.
p.s.i'm a newbie here, so please explain this thoroughly ;)
#pragma strict
var speed = 5;
var rotSpeed = 120;
var turret : GameObject;
var power = 600;
var bullet : Transform;
var explosion: Transform;
var snd : AudioClip;
function Update() {
var amtToMove = speed * Time.deltaTime;
var amtToRot = rotSpeed * Time.deltaTime;
var front = Input.GetAxis("Vertical");
var ang = Input.GetAxis("Horizontal");
var ang2 = Input.GetAxis("MyTank");
transform.Translate(Vector3.forward * front * amtToMove);
transform.Rotate(Vector3(0, ang * amtToRot, 0));
turret.transform.Rotate(Vector3.up * ang2 * amtToRot);
function Update(); {
...................;
if (Input.GetButtonDown("Fire1")) {
var spPoint = GameObject.Find("spawnPoint");
Instantiate(explosion, spPoint.transform.position, Quaternion.identity);
AudioSource.PlayClipAtPoint(snd, spPoint.transform.position);
var myBullet = Instantiate(bullet, spPoint.transform.position, Quaternion.identity);
myBullet.rigidbody.AddForce(spPoint.transform.forward * power);
}
And now the errors...
Assets/jstank/jstank.js(73,1): BCE0044: expecting }, found ''.
Assets/jstank/jstank.js(55,5): BCE0043: Unexpected token: ..
Assets/jstank/jstank.js(55,4): BCE0043: Unexpected token: ..
Assets/jstank/jstank.js(53,10): BCE0044: expecting (, found 'Update'.
Answer by DaveA · Jul 12, 2012 at 08:06 PM
You have garbage. Delete this:
function Update(); {
...................;
Answer by blackmethod · Jul 12, 2012 at 08:16 PM
Okay. Lots wrong here, no offence. You're missing tons of curly-braces. And never put a semi-colon before a curly brace. Otherwise you're essentially telling it to stop the function but keep going. Of course it's confused.
#pragma strict
var speed = 5;
var rotSpeed = 120;
var turret : GameObject;
var power = 600;
var bullet : Transform;
var explosion: Transform;
var snd : AudioClip;
function Update() {
var amtToMove = speed * Time.deltaTime;
var amtToRot = rotSpeed * Time.deltaTime;
var front = Input.GetAxis("Vertical");
var ang = Input.GetAxis("Horizontal");
var ang2 = Input.GetAxis("MyTank");
transform.Translate(Vector3.forward * front * amtToMove);
transform.Rotate(Vector3(0, ang * amtToRot, 0));
turret.transform.Rotate(Vector3.up * ang2 * amtToRot);
if (Input.GetButtonDown("Fire1")) {
var spPoint = GameObject.Find("spawnPoint");
Instantiate(explosion, spPoint.transform.position, Quaternion.identity);
AudioSource.PlayClipAtPoint(snd, spPoint.transform.position);
var myBullet = Instantiate(bullet, spPoint.transform.position, Quaternion.identity);
myBullet.rigidbody.AddForce(spPoint.transform.forward * power);
}
}
Code is very messy but try that, it might work.
As for what you have, I don't see why you have 2 update functions, you only need one.
And putting " ...................;" it's expecting a command. The only way you can put something without having it affecting the code is making sure to put "//" before it.
thanks a million, nathan! the game is quite fluently running but the tank don't know how to shoot:( there's the error... help me please
UnassignedReferenceException: The variable explosion of 'jstank' has not been assigned. You probably need to assign the explosion variable of the jstank script in the inspector. UnityEngine.Object.Internal_InstantiateSingle (UnityEngine.Object data, Vector3 pos, Quaternion rot) (at C:/BuildAgent/work/b0bcff80449a48aa/Runtime/ExportGenerated/Editor/UnityEngineObject.cs:44) UnityEngine.Object.Instantiate (UnityEngine.Object original, Vector3 position, Quaternion rotation) (at C:/BuildAgent/work/b0bcff80449a48aa/Runtime/ExportGenerated/Editor/UnityEngineObject.cs:53) jstank.Update () (at Assets/jstank/jstank.js:53)
From what you posted the only solution I have is... When you apply the script to the gameobject in the "inspector" it becomes active, but with your script it's trying to activate something that isn't there if you get me. You have an explosion set to happen, but the explosion effect itself isn't part of the script. So if you were to click on the item in the inspector with the script on it you would get something like this.
It would have all the usual gameobject info, then scroll down to where it shows the script in the object, there should be a blank spot that you can drag and drop an explosion prefab animation onto.
Prefab = Predefined object or set of objects that can be dropped into the game at any time
Inspector = The box in the bottom left showing objects in the scene
Gameobject = Item that you can see in the inspector, that is in the scene
Hope I helped you out, if I did please thumbs up my first post!