Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
This question was closed Dec 31, 2015 at 09:05 PM by Warhulk1745 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Warhulk1745 · Dec 31, 2015 at 07:22 PM · vector3floatconvertcommunication

Reference Vector 3 variable to float variable.

Hello everyone !

I have a problem and it's killing me a little inside each time I can't fix it. My main goal is to have var XP and var size communicating with each other. I need var XP to feed numbers to var size. Please help me out with this !

   #pragma strict
     
      public var XP : float;                  // This variable will feed numbers to var size.
      public var randomRangeXP : float;
      public var size : Vector3;         // This variable will take the numbers from var XP.
      
     
     function Update ()
             {
             XP += randomRangeXP = XP ;  
 
            // I need a line that will take the number from var XP and feed it to var size.  
            }
     
 
           function OnTriggerEnter(other : Collider)
             {
                 if (other.gameObject.tag == "Bacteria")
                 Destroy(other.gameObject);
            
  // Once I have that line that will feed var size, I'll have another line here that will make my                     character bigger depending on the XP given. 
             }


I hope you guys understand what I want to do, I tried to be as clear as possible, I'm new to code so please be gentle ! Thank you all for your time !

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 Socapex · Dec 31, 2015 at 07:30 PM 0
Share

I'm trying to figure out what you are doing, but it is really hard with the broken code formatting. Could you please edit the question to put all the code inside a code block? please :)

2 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by Socapex · Dec 31, 2015 at 07:37 PM

Wild guess: You want to increment the size using XP and a little bit of randomness. I will write C#.

 // Increase size using +- 2 of the XP
 float incrementSize =  Random.Range(XP - 2, XP +2);
 size.x += incrementSize;
 size.y += incrementSize;
 size.z += incrementSize;
 
 // Increase size by a fixed amount, the quantity of XP. XP == size
 size.x = XP;
 size.y = XP;
 size.z = XP;

Close?

Comment
Add comment · Show 4 · 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 Warhulk1745 · Dec 31, 2015 at 07:44 PM 0
Share

Sorry for the mess. I'm new to code and I'm still learning.

I went ahead and revised it again and made it neater.

I don't need randomness, that part I've already taken care of.

What I really need is to be able to give variable size the value from variable XP. But because variable size is a Vector3, it's not communicating with variable XP.

avatar image Socapex Warhulk1745 · Dec 31, 2015 at 07:51 PM 0
Share

Then the second part should do it, you can +=, -=, /=, *= and = the value. You can work on the individual parts of the vector (x,y,z) with floats. Think of a vector3 as a fancy array of float[3]

By communicating I am guessing you mean transform the vector3 in some way.

avatar image Warhulk1745 Socapex · Dec 31, 2015 at 08:26 PM 0
Share

I have no idea how to translate your response to Javasript lol. $$anonymous$$aybe something I should have mentioned is "I'm working with Javascript".

Show more comments
avatar image
0

Answer by Warhulk1745 · Dec 31, 2015 at 09:04 PM

 #pragma strict
 
  public var XP : float;
  public var randomRangeXP : float;
  public var size : Vector3;
 
 
 
  function Start () {
   
   randomRangeXP = Random.Range (5.00,50.00);
  }
 
 function Update () {
                                        
     XP == size ;
     size.x =XP;
     size.y = XP;
     size.z = XP;
 
 }
 
 
 function OnTriggerEnter(other : Collider)
     {
         if (other.gameObject.tag == "Bacteria")
             Destroy(other.gameObject);
        
               transform.localScale += size ;
               XP += randomRangeXP; 
        
       //  transform.localScale += new Vector3(20,20,20);
 
     }

So, part of my problem was that I had two scripts and I wasn't accessing variables from my other script the right way. So what I ended up doing was putting everything in one single script. The code I'm using is allowing the two variables to communicate how I needed them to. Thanks Socapex !

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 Socapex · Dec 31, 2015 at 09:18 PM 0
Share

Glad it worked :)

Follow this Question

Answers Answers and Comments

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

Related Questions

Why are my Vector3s returning inaccurate floats? I don't think it's the debug .ToString() issue. 2 Answers

Cannot convert float to int? 1 Answer

Non physics determinism of floating point math across platforms 1 Answer

The moving average (filter) of the acquired value of the HTC vive controller 0 Answers

float.Parse changing dot position 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