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 /
This question was closed Jul 16, 2015 at 08:03 PM by timohausmann for the following reason:

Not possible

avatar image
0
Question by timohausmann · Apr 12, 2015 at 09:32 PM · javascriptstatic-vars

Unityscript: Possible to access static variables dynamically?

Hi, I'm just starting with Unity and I'm struggling to access static variables like Vector3.up, Vector3.down dynamically. I want to check possible collisions via Raycast in a loop, so this is what I ended up with:

 public var rays : Hashtable = new Hashtable();
 
 function Update() {
     var directions = ["forward", "left", "right", "up", "down"];
     for(var dir : String in directions) {

         var tmpRay : RaycastHit;
         var tmpBool : boolean = Physics.Raycast( transform.position, 
             transform.TransformDirection(Vector3[dir]), 
             tmpRay, 
             1 );    

         rays[dir] = tmpRay;
         rays['is'+dir] = tmpBool;
     }
 }

When I try to access the static variables of Vector3 (forward, left etc.) via iteration (I tried Vector3[dir] for this), I get:

 BCE0048: Type 'System.Type' does not support slicing.
 

In Javascript this would work.

Is there any way to access static variables like this?

I'm beginning to wonder if there is any reason to use UnityScript if I can't play with objects like I'm used to in Javascript. Thanks for any advice!

Edit: from what I can tell after a few hours with UnityScript: normal loose Javascript objects don't work at all in Unity. I have to get my head around Unitys data structures. Correct me if I'm wrong :)

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

  • Sort: 
avatar image
0

Answer by tanoshimi · Apr 12, 2015 at 09:34 PM

Don't use UnityScript myself, but would this not work?

 function Update() {
      var directions = [Vector3.forward, Vector3.left, Vector3.right, Vector3.up, Vector3.down];
      for(var dir : Vector3 in directions) {
          var tmpRay : RaycastHit;
          Physics.Raycast( transform.position, 
              transform.TransformDirection(dir), 
              tmpRay, 
              1 );    
          rays[dir] = tmpRay;
      }
  }
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 timohausmann · Apr 12, 2015 at 09:55 PM 0
Share

Hey, thanks for taking a look! Apparently reading the values later like rays[Vector3.down] does not work this way. (Writing them in line 9 throws no Errors though O.o)

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

[--FIXED--][UPDATE#5][VIDEO]Instantiating problem(OLD TITLE:How do I change the static variable of one object instead of all instances 3 Answers

Do static variables carry values between Clients? 1 Answer

Why cant I subtract point from my score? 1 Answer

Changing variables in GUI? 0 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