Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Codes broken after conversion from c# to javascript

Discussion in 'Scripting' started by Anubi5, Jul 16, 2013.

  1. Anubi5

    Anubi5

    Joined:
    Jul 16, 2013
    Posts:
    1
    {
    public var moveSpeed: float = 1.0;

    public var bullet: GameObject;

    @HideInInspector
    public var originalBullet: GameObject;

    public var bulletSpeed: float = 1.0;
    public var shootDelay: float = 0.2;

    private var canShoot: boolean = true;

    private function Start()
    {
    originalBullet = bullet;
    }

    private function FixedUpdate()
    {
    var moveDirection: Vector3 = new Vector3(Input.GetAxis("Horizontal"),Input.GetAxis("Vertical"), 0);

    rigidbody.MovePosition(transform.position + moveDirection*moveSpeed*Time.deltaTime);
    //transform.position += moveDirection*moveSpeed*Time.deltaTime;

    if((Input.GetAxis("FireHorizontal") != 0.0 || Input.GetAxis("FireVertical") != 0.0) canShoot)
    {
    var shootDirection: Vector3 = new Vector3(Input.GetAxis("FireHorizontal"),Input.GetAxis("FireVertical"), 0).normalized;
    var bulletInstance: GameObject = Instantiate(bullet,transform.position,Quaternion.LookRotation(shootDirection)) as GameObject;
    bulletInstance.rigidbody.AddForce(shootDirection*bulletSpeed,ForceMode.VelocityChange);
    canShoot = false;
    Invoke("ShootDelay", shootDelay);
    }
    }

    private function OnCollisionEnter()
    {
    rigidbody.velocity = Vector3.zero;
    }
    private function OnCollisionExit()
    {
    rigidbody.velocity = Vector3.zero;
    }

    private function ShootDelay()
    {
    canShoot = true;
    }
    }
     
  2. Mister-E2

    Mister-E2

    Joined:
    Jun 6, 2013
    Posts:
    179

    That's because it is badly converted to javascript
     
  3. tonyd

    tonyd

    Joined:
    Jun 2, 2009
    Posts:
    1,224
    You should be getting a whole bunch of errors in the console... you just need to fix them all.

    You should start by removing the first pair of leading and trailing braces, as you don't need those. Next remove 'private' from all Monobehaviour functions, as these are supposed to be public... if you make them private, they won't be called automatically (and the console will tell you this... 'Private method XXX is never used').

    Finally, you've got extra spaces in several places (Input.GetA xis, for instance).