Switch Syntax

I’m changing my c# scripts into JS, but getting some errors.

	var target : GameObject;
	var attackTimer;
	var coolDown : float;
	

	// Use this for initialization
	function Start () {
		attackTimer = 0;
		coolDown =1.2f;
	
	}
	
	// Update is called once per frame
	function Update () {
		if(attackTimer > 0)
			attackTimer -= Time.deltaTime;
		
		if(attackTimer < 0)
			attackTimer = 0;
		
		if(Input.GetKeyUp(KeyCode.F)) {
			if(attackTimer == 0){
			Attack();
				attackTimer = coolDown;
			}
		}
	
	}
	private function Attack(){
		var distance = Vector3.Distance(target.transform.position, transform.position);
		
		Vector3 dir = (target.transform.position - transform.position).normalized;
		
		var direction = Vector3.Dot(dir, transform.forward);
		
		Debug.Log(direction);
		
		if(distance < 4) {
			if(direction > 0){
	//ATTACK CODE HERE
			}
			}
		}

But i’m getting this error Assets/PlayerAttack1.js(32,24): UCE0001: ‘;’ expected. Insert a semicolon at the end.

Hmmm.

Hmmm.

Is it possible to call a JS Function from a C# script? Like if curHealth = 0(Call the function “Spawn” From a js)

Yes.

Though there may be some tricks.

I haven’t had to deal with it much.

I think the following line of code;

Vector3 dir = (target.transform.position - transform.position).normalized;

needs to be changed to be;

var dir : Vector 3 = (target.transform.position - transform.position).normalized;

oh… wow, how did i miss that :confused: But anyone know if you can call functions from a JS from a C# script?

You can use SendMessage between languages, or if you place the scripts in the right directory so they are compiled in the right order then you can as well. I’ve come to the conclusion that it’s best to just do everything in C# though and not worry about it.