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 /
avatar image
0
Question by Brosilio_Gaming · Aug 31, 2015 at 05:23 PM · c#javascript

Help converting a few lines of JS to C#.

I need help with this code. everything here seems to be NOT throwing errors, the one that shows the positioning of the "levelBar" is (the really long line) throws the error: "Assets/SpaceOverload/Scripts/experiencemanager.cs(18,49): error CS0119: Expression denotes a type', where a variable', value' or method group' was expected"

here is the code before and after: (im 13, and just started learning C# about a month ago, so if you explain it, please explain it in a way i can understand)

JAVASCRPIT

 #pragma strict
 
 //here are public variables that are accessed in the inspector. this script manages the experience bar and the level text at the top of the screen.
 var levelText:GUIText;
 var levelBar:GUITexture;
 var bar1:GUITexture;
 var lvlUpSound:AudioClip;
 
 //these keep track of amount of experience and level number
 var expAmount:float = 0.0;
 private var level:int = 1;
 
 function Update () {
 //make sure the blue part of the level bar stays the same height as the white and black bar while changing resolution
 levelBar.transform.localScale = Vector3(0.24*(expAmount/(45*level)),bar1.transform.localScale.y,1);
 
 //this checks to see if theres enough experience to level up. for this simple example we made it take 45 orbs more for every level to level up.
 if(expAmount >= (45*level)){
 //play the level up sound if we level up.
 GetComponent.<AudioSource>().PlayOneShot(lvlUpSound);
 //exp goes back to 0 so the bar is blank again.
 expAmount = 0;
 // add a level
 level += 1;
 // update the level text at the top to show the new level
 levelText.text = "Lvl " + level.ToString();
 //this message is received by weapons so they can keep track of the level and get better as well. 
 SendMessage("levelup", level, SendMessageOptions.DontRequireReceiver);
 }
 }
 
 //if an orb hits the player, we gain experience. (expAmount)
 function OnTriggerEnter (other : Collider){
 if(other.name == "exp(Clone)"){
 expAmount += 1;
 Destroy(other.gameObject);
 }
 if(other.tag == "XPMultiplier"){
 expAmount *= 2;
 }
 }

WHAT I TURNED INTO C#. LINE 18 throws errors

 using UnityEngine;
 using System.Collections;
 
 public class experiencemanager : MonoBehaviour {
 
     public GUIText levelText;
     public GUITexture levelBar;
     public GUITexture bar1;
     public AudioClip lvlUpSound;
     public float expAmount = 0.0f;
     public int level = 0;
     private AudioSource source;
 
 
     
     // Update is called once per frame
     void Update () {
         levelBar.transform.localScale = Vector3 (0.24 * (expAmount / (45 * level)), bar1.transform.localScale.y, 1);
 
         if (expAmount >= (45 * level)) {
             source = GetComponent<AudioSource>();
             expAmount = 0;
             level += 1;
             levelText.text = "Level " + level.ToString();
             SendMessage("levelup", level, SendMessageOptions.DontRequireReceiver);
             source.PlayOneShot(lvlUpSound);
         }
     }
     void OnTriggerEnter (Collider other) {
         if (other.name == "exp(clone)") {
             expAmount += 1;
             GameObject.Destroy(this);
         }
     if (other.tag == "XPMultiplier") {
             expAmount *= 2;
         }
     }
 }
 



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

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

Answer by Scribe · Aug 31, 2015 at 05:27 PM

you need the 'new' keyword (and also an f after a floating point number to notify the compiler that it is a float):

 new Vector3 (0.24f * (expAmount / (45 * level)), bar1.transform.localScale.y, 1);

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 Brosilio_Gaming · Aug 31, 2015 at 05:35 PM 0
Share

@scribe haha totally forgot the 'f' XD thanks and thanks for the immidiate help :D

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

32 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

Related Questions

Any way to use UI on a screen renderer? 0 Answers

addComponent c# script by java 0 Answers

Jump Issue :( 1 Answer

SHA512 JS -> C# 0 Answers

Make object fall when user enters space 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