• 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 Jordan Miller 2 · Jul 28, 2010 at 12:26 AM · translatelocalposition

translate from JavaScript to C#?

how do I translate this

transform.localPosition = Vector3(0, 0, 0);

to C# code?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Mike 3 · Jul 28, 2010 at 12:31 AM

transform.localPosition = new Vector3(0, 0, 0);

You'll always need to use new when creating an instance of a new object in c#, it's optional (except a couple of cases) in js

Comment
Add comment · Show 1 · 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
avatar image Cyclops · Jul 28, 2010 at 01:40 AM 2
Share

@$$anonymous$$ike, did we forget the all-important link? :) http://answers.unity3d.com/questions/5507/what-are-the-syntax-differences-in-c-and-javascript

avatar image
0

Answer by Sija · Mar 23, 2013 at 05:01 PM

hi I've trayed translate that:

 var holdTime = 0.5;
     var activeCamera : Camera;  // W edytorze wybierz aktywna kamere (ta z FirstPersonControler'a)
     var buttonRect : Rect;
     var showGUI = false;
     var fade : float = 0.0;
     var myText = "Hover Text";
     var GUISizeX = 200;
     var GUISizeY = 90;
     private var timer : float = 0.0;
     private var originalColor;
     var highlightMultiply = 1.50;
      
     function Start() 
     {
             originalColor = renderer.material.color;   
     }
      
     // Akcja po najechaniu na obiekt
     function OnMouseOver() 
     {
         if (!Application.isPlaying)
             return;
         timer += Time.deltaTime;
         if(timer >=0.25)    
             {   
             buttonPosn = activeCamera.WorldToScreenPoint(gameObject.transform.position);
            
             //Ustaw pozycje GUI
             buttonRect = Rect(buttonPosn.x, buttonPosn.y, GUISizeX, GUISizeY);
             showGUI = true;
             timer = 0.0;
             }
        
         if((timer != 0) )   
             {
             renderer.material.color.r = originalColor.r*highlightMultiply;
             renderer.material.color.g = originalColor.g*highlightMultiply;
             renderer.material.color.b = originalColor.b*highlightMultiply;
             renderer.material.color.b = renderer.material.color.b*highlightMultiply;
             }  
     }
      // Klikniecie przycisku.
     function OnMouseDown() 
     {
         if (!Application.isPlaying)
             return;
            
   
         Application.OpenURL("http://google.pl");
        
     }
      
     function OnMouseExit() {            // wyjscie z podswietlenia
         if (!Application.isPlaying)
             return;
            
         showGUI = false;
         timer = 0.0;
         yield new WaitForSeconds(0.1);
        
         // Ustaw kolor na domyslny
         renderer.material.color.r = originalColor.r*highlightMultiply;
         renderer.material.color.g = originalColor.g*highlightMultiply;
         renderer.material.color.b = originalColor.b*highlightMultiply;
         renderer.material.color.b = renderer.material.color.b/highlightMultiply;
         renderer.material.color = originalColor;
     }
      
     function OnGUI() {
       var saveColor= GUI.color;
      
       if(showGUI) {
            
             saveColor= GUI.color;
             GUI.color.a = fade;
             GUI.Box (buttonRect, myText);
        
           
             GUI.color = saveColor;
             FadeIn();
        }
        else  {
            
             saveColor= GUI.color;
             GUI.color.a = fade;
             GUI.Box (buttonRect, myText);
        
           
             GUI.color = saveColor;
             FadeOut();
        }
     }
      
     function FadeIn() {
      
        while(fade < 1.0)   {
           fade += Time.deltaTime / 2;
       
           yield;
        }
        fade = 1;
     }
      
     function FadeOut() {
        // Zanikanie z przezdiału 2 sekund
        while(fade > 0.0)   {
           fade -= Time.deltaTime / 2;
           yield;
        }
        fade = 0;
     }

script but is so hard:( anyone can translate that?

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
avatar image
0

Answer by jashan · Jul 28, 2010 at 08:40 AM

Actually, a more interesting question would be how to convert this from JavaScript to C#:

transform.localPosition.x = 3;

Because in C#, that won't work (and actually, even in JavaScript there's a little more to it than meets the eye ;-) ). So here is how that's done in C#:

Vector3 pos = transform.localPosition;
pos.x = 3;
transform.localPosition = pos;

EDIT: Just noticed this was missing in What are the Syntax Differences in C# and Javascript?, so I've added (with some extra explanation on why this is the case).

Comment
Add comment · Show 1 · 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
avatar image jashan · Jul 29, 2010 at 12:00 PM 0
Share

Oh oh ... you're so right ... wonder how that got lost, must've been copying stuff around. Thanks for the heads up! Fixed ;-)

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

Multiple Coordinate Systems 1 Answer

C# to javascript 2 Answers

Translate character forward at certain points in animations 0 Answers

Moving a GameObject towards a CharacterController 1 Answer

Move object forward 1 unit then stop 2 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