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 tauch33 · Nov 06, 2014 at 09:32 PM · boolean

Can't translate bool from C# to unityscript

I am trying to convert this part of a script from C# to unityscript.

PART OF IT:

public bool CanAttack { get { return shootCooldown <= 0f; } }

I don't know much of C#, I was used of seeing ; in the end, or of function which started with public void ... But this has none of it. And I am not sure how to do it, is this the right way? :

public var CanAttack : boolean; { get { return shootCooldown <= 0f; }

}

Comment
Add comment · Show 1
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 tauch33 · Nov 07, 2014 at 05:36 PM 0
Share

It works now. SOLUTION:

 public function get CanAttack() : boolean
       
      {
       return shootCooldown <= 0f;
      }
 

2 Replies

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

Answer by troien · Nov 06, 2014 at 09:42 PM

The piece of code you show there is called property in C#.

See this post for how you can do this in javascript.

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 tauch33 · Nov 07, 2014 at 05:34 PM 0
Share

Thank you really much, I found the solution there.

avatar image
0

Answer by FairGamesProductions · Nov 06, 2014 at 10:21 PM

This may be a little un-orthodox, but the simplest way I found to transfer variables from any script to any other script, without depending on compile order or any of that mess, are empty GameObjects (for bool variables). For example (JS):

 private var MyBooleEmptyGameObject : GameObject;
 private var BoolInThisScript = false;
 
 function Start ()
     {
     MyBooleEmptyGameObject = GameObject.Find ("/Variables/MyBooleEmptyGameObject");
     if (MyBooleEmptyGameObject.transform.localPosition.y > 0.5)
         {
         BoolInThisScript = true;
         }
     else
         {
         BoolInThisScript = false;
         }
     }

I usually keep all my Empty GameObject variables under another Empty GameObject called "Variables", to keep things neat. I also use the 0.5 Y position as the threshold between true and false, as sometimes in Unity GameObjects MAY change their position by 0.000000001 So using > 0.5 or < 0.5 is the safe bet.

The same process can be done with string, int or float.

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 tauch33 · Nov 07, 2014 at 05:37 PM 0
Share

Thank you.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Mecanim Boolean 1 Answer

Shields 'always' inactive. Player object doesn't recognise if child exists(Solved) 1 Answer

Detect perimetral walls of a room 1 Answer

Spawn Object If Boolean Equals True, Boolean Set To True On Level Load 1 Answer

Error : Animator has not been initialized. UnityEngine.Animator:SetBool(String, Boolean) 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