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 ogprestar · Apr 12, 2012 at 11:43 PM · c#javascriptconvert

java to C#

hi am trying to create a simple GUItexture that will change depending on collision with an item the code in java is: please change to c#

 static var Life : int = 0;
 
 var Threelife : Texture2D;
 var Twolife : Texture2D;
 var Onelife : Texture2D;
 var Nolife : Texture2D;
 
 function Start () {
     Life = 0;
 }
 
 function Update () {
     if(Life == 1){
         guiTexture.texture = Twolife;
     }
     else if (Life == 2){
         guiTexture.texture = OneLife;
     }
     else if (Life >= 3) {
         guiTexture.texture = NoLife;
     }
     else {
         guiTexture.texture = ThreeLife;
     }
 }
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

2 Replies

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

Answer by rutter · Apr 13, 2012 at 01:10 AM

This looks like an easy script to translate.

 //javascript
 var Threelife : Texture2D;
 
 //C#
 public Texture2D Threelife;

 //javascript
 function Start() { ... }

 //C#
 void Start() { ... }

If you're really having that much trouble, this isn't necessarily a good place to learn C# -- luckily there are numerous tutorials around the net that can help you with that.

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 AlucardJay · Apr 13, 2012 at 03:05 AM 1
Share

I agree. Try it for yourself , you will learn to understand both unityscript and C#.

Reference : http://answers.unity3d.com/questions/12911/what-are-the-syntax-differences-in-c-and-javascrip.html

Online Converter : http://files.m2h.nl//js_to_c.php

avatar image
-4

Answer by Danpe · Apr 13, 2012 at 01:11 AM

C#

 public static int Life = 0;
 public Texture2D Threelife, Twolife, Onelife, Nolife;
 
 void Start () 
 { 
     Life = 0; 
 }
 
 void Update () 
 { 
     if(Life == 1)
     { 
         guiTexture.texture = Twolife; 
     }
     else if (Life == 2)
     { 
         guiTexture.texture = OneLife; 
     }
     else if (Life >= 3) 
     { 
         guiTexture.texture = NoLife; 
     }
     else 
     { 
         guiTexture.texture = ThreeLife; 
     } 
 }
Comment
Add comment · Show 2 · 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 Bunny83 · Apr 13, 2012 at 02:23 AM 1
Share

This isn't really C#. First there is no "function" keyword like in Unityscript, second i guess your texture variables should be public. The default visibility in C# is private.

avatar image Tseng · Apr 13, 2012 at 02:45 AM 1
Share

Also the class declaration is missing ;)

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

7 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

this script in Javascript?? 0 Answers

Help with conversion from javascript to c# 3 Answers

Can someone help me translate this to c#? 1 Answer

error CS1061 anybody might help me? 1 Answer


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