- Home /
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();
}
}
}
You might trade print(...) for Debug.Log(...). $$anonymous$$onoBehaviour does have an undocumented print() function, but I wouldn't rely on it.
Thanks for the suggestion but sadly it didn't work :/
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();
}
}
Ha! Thanks! I knew it had to do with the brackets! Thanks a lot man!
Your answer
Follow this Question
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