Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ineteye · Oct 14, 2012 at 11:35 AM · c#

Need help converting js to C#

hI! i got a strange result after conversing js-to-C# on mouse action... so is this two codes same?

Js code:

 #pragma strict
 #pragma implicit
 #pragma downcast
 
 static var destroyed:int=0;
 public var container :GameObject;
 var scoreParticle:GameObject;
 
 
 function Update()
 {
     if (Input.GetButtonDown("Fire1")) 
     {
            var ray = GetComponent.<Camera>().ScreenPointToRay (Input.mousePosition); //ray from camera to mouse position, we use this for clicking on balls
            var hit : RaycastHit; 
            if ( Physics.Raycast (ray, hit, 30.0) ) //if we hit something
            { 
                if(hit.rigidbody)
                { //and it is rigidbody
                   object=hit.collider.transform.position;  // hitted object's position
                 hit.collider.gameObject.GetComponent.<chack>().Start(); //enable hitted object's chack script,
                 if(destroyed <= 0 && (int.Parse(container.GetComponent(instantiate).score) >= 10))
                 { //if we clicked and don't destroyed any balls
                     var minusScore=Instantiate(scoreParticle, object - Vector3(0,0,0.3), Quaternion.identity) as GameObject; //instantiate scoreParticle
                     container.GetComponent(instantiate).score=""+(int.Parse(container.GetComponent(instantiate).score) - 30); //minus 10 to score text
                 }
             }
         }         
     }
 }

C# code:

 using UnityEngine;
 using System.Collections;
 
 public class test : MonoBehaviour 
 {
 
 static int destroyed=0;
 public GameObject container;
 GameObject scoreParticle;
 private Vector3 obj;
 void Update ()
 {
     if (Input.GetButtonDown("Fire1")) 
     {
            Ray ray= GetComponent<Camera>().ScreenPointToRay(Input.mousePosition); //ray from camera to mouse position, we use this for clicking on balls
         //Ray ray = camera.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit; 
            if ( Physics.Raycast (ray,out hit, 30.0f) ) //if we hit something
            { 
                if(hit.rigidbody)
                { //and it is rigidbody
                   obj=hit.collider.transform.position;  // hitted object's position
                 hit.collider.gameObject.GetComponent<chack>().Start(); //enable hitted object's chack script,
                 if(destroyed <= 0 && (int.Parse(container.GetComponent<instantiate>().score) >= 10))
                 { //if we clicked and don't destroyed any balls
                     GameObject minusScore=(GameObject)Instantiate(scoreParticle, obj - new Vector3(0,0,0.3f), Quaternion.identity); //as GameObject; //instantiate scoreParticle
                     container.GetComponent<instantiate>().score=""+(int.Parse(container.GetComponent<instantiate>().score) - 30); //minus 10 to score text
                 }
             }
         }         
     }
 }
 }

Cause in js script used is "hit", but in C# i have to use "out hit"

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Kalmak · Oct 14, 2012 at 03:06 PM

I didn't notice anything wrong at a glance. Here is some info on the out keyword and passing by reference in C#: http://msdn.microsoft.com/en-us/library/t3c3bfhx(v=vs.80).aspx

M2H has a good converter in the asset store. If you don't have the funds to buy it they have an older free version here: http://files.m2h.nl//js_to_c.php

K

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Enemy AI script causing Unity to crash (Javascript to C#) 1 Answer

Need help converting js to C 2 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Need help converting js to C# -- yield return WaitForSeconds 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges