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 bartleycollin · Oct 31, 2013 at 01:13 AM · errorconsole

My C# script brings back no results in the console

I've been working on my C# more and more lately, and I've been messing around with the Object Oriented side of things. I made this script following a lesson, and it has no errors. When I attach it to my Camera and press play, it comes up with no results in the console. Any thoughts?

 using UnityEngine;
 using System.Collections;
 
 public class myWeapons2 : MonoBehaviour {
   
   //Weapon-Class-Start---------------------------
   public class aWeapon {
 
     //Properties of a weapon
     public string name; 
     public int power; 
     public int weight;
         
     //A method = A function that does somthing.
     public void weaponData(){
       print("Name: " + name);
       print("Power: " + power);
       print("Weight: " + weight); 
   }
   //Weapon-Class-End------------------------------
  
 //Create-Weapons-Start----------------------------
    
    void Start (){
      aWeapon Bow = new aWeapon();//Creates a Bow   
      aWeapon Sword = new aWeapon();//Creates a Sword
      aWeapon Hammer = new aWeapon();//Creates a Hammer
 
 //Create-Weapons-End------------------------------     
        
     //Set-Weapon-Properties-----------------------
     Bow.name = "Bow";
     Bow.power = 45;
     Bow.weight = 15;
     
     Sword.name = "Sword";
     Sword.power = 60;
     Sword.weight = 35;
     
     Hammer.name = "Hammer";
     Hammer.power = 80;
     Hammer.weight = 55;
     
     //Call the Weapon Methods
     Bow.weaponData();
     Sword.weaponData();
     Hammer.weaponData();
     
     }
   } 
 }
 
 
Comment
Add comment · Show 2
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 rutter · Oct 31, 2013 at 01:16 AM 0
Share

You might trade print(...) for Debug.Log(...). $$anonymous$$onoBehaviour does have an undocumented print() function, but I wouldn't rely on it.

avatar image bartleycollin · Oct 31, 2013 at 01:20 AM 0
Share

Thanks for the suggestion but sadly it didn't work :/

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by eskimojoe · Oct 31, 2013 at 01:30 AM

There is a bracing error. At line 21, please add an extra } brace.

Then the codes will work.

 using UnityEngine;
 using System.Collections;
 
 public class a1 : MonoBehaviour {
 
     //Weapon-Class-Start---------------------------
     public class aWeapon {
 
         //Properties of a weapon
         public string name;
         public int power;
         public int weight;
 
         //A method = A function that does somthing.
         public void weaponData() {
             Debug.Log("Name: " + name);
             Debug.Log("Power: " + power);
             Debug.Log("Weight: " + weight);
         }
         //Weapon-Class-End------------------------------
     }
     //Create-Weapons-Start----------------------------
 
     public void Start() {
         Debug.Log("Start");
         aWeapon Bow = new aWeapon(); //Creates a Bow   
         aWeapon Sword = new aWeapon(); //Creates a Sword
         aWeapon Hammer = new aWeapon(); //Creates a Hammer
 
         //Create-Weapons-End------------------------------   
 
         //Set-Weapon-Properties-----------------------
         Bow.name = "Bow";
         Bow.power = 45;
         Bow.weight = 15;
 
         Sword.name = "Sword";
         Sword.power = 60;
         Sword.weight = 35;
 
         Hammer.name = "Hammer";
         Hammer.power = 80;
         Hammer.weight = 55;
 
         //Call the Weapon Methods
         Bow.weaponData();
         Sword.weaponData();
         Hammer.weaponData();
 
     }
 }
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 bartleycollin · Oct 31, 2013 at 01:43 AM 0
Share

Ha! Thanks! I knew it had to do with the brackets! Thanks a lot man!

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

17 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

Related Questions

Why do I get this error 0 Answers

What's the matter with my Cube.fbx? 0 Answers

Console Error 1 Answer

A node in a childnode? 1 Answer

How to fix this error, source included. 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