Trying to print using C#

Ok so I have this little game I am working on and I am tring to get some output for the user when he hits the enemy I would like to print out something so the player can see hey I hit the opponet. Just some simple line somewhere so I can test to see if my code is acctually doing something.
I have tried print(“something”);
and also Console.Writeline(“something”);
too see if I did the scripting right;
Thanks:)
here is the code:

using UnityEngine;
using System.Collections;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;


public class Battle : MonoBehaviour {
	
		//build and initialization of characters in the game
		//do this somewhere else in real game
		//build character 1
		Player Mav = new Player();
		
		//build enemy ninja
		Enemy Ninja = new Enemy();
		
	public double potion = 100;//hp boost
	public double elixer = 200;//hp boost
	
	

	// Use this for initialization
	void Start () {
		

		Mav.hp = 1220;
		Mav.mp = 150;
		Mav.sp = 100;
		Mav.charaterName = "Mavrick";
		
		//initialization of attacks and skill wheel
		Mav.slash = 1;
		Mav.flameSlash = 1.5;
		Mav.shiningStrike = 2;
		
		//skill wheel
		Mav.powerDive = 150;
		Mav.powerCharge = 250;
		Mav.wildStrike = 350;
		Mav.renegade = 400;
		Mav.shiningStars = 500;
		
		//magic
		Mav.lightSpell = 150;
		Mav.flame = 150;
		Mav.snow = 300;
		
		
		//initialization of enemy
		Ninja.hp = 1000;
		Ninja.atk1 = 100;
		Ninja.atk2 = 150;
		Ninja.specialAttack = 200;
		Ninja.enemyName = "Ninja";
		
	}
	
	// Update is called once per frame
	void Update () {
		battle();
				
	}
	
	
	void battle()
	{
		//see if enemy dies
		while(Ninja.hp > 0){
			
		//random number for attack power Not C# but unity engine random number
		int dice = UnityEngine.Random.Range(1,50); 
		string bInput;
		char button;
        bInput = Console.ReadLine();
        button = char.Parse(bInput);
		
		switch (button)
                {
					//slash attack
                    case 'x':
                        Ninja.hp = Ninja.hp - (Mav.slash * dice);
						Console.WriteLine("Slash Attack");
						print("Slash Attack");
						print(Ninja.hp);

                        Thread.Sleep(5000);//sleep for 5 second Player cant attack
                        
                        break;

					//flame slash attack
                    case 'v':

                        Ninja.hp = Ninja.hp - (Mav.flameSlash * dice);
						
                        Thread.Sleep(5000);//sleep for 5 second Player cant attack
                        
                        break;

					//shining Srike attack
                    case 's':

                        Ninja.hp = Ninja.hp - (Mav.shiningStrike * dice);
				        
                        Thread.Sleep(5000);//sleep for 5 second Player cant attack
                        
                        break;

					//skill wheel attacks
                    case 'l':
                    /*    
					Console.WriteLine("Skill Wheel");
                        Console.WriteLine("1 for Power Dive");
                        Console.WriteLine("2 for Power Charge");
                        Console.WriteLine("3 for Wild Strike");
                        Console.WriteLine("4 for Renegade");
                        Console.WriteLine("5 for Shining Stars");
					*/
                    
						string b1Input;
                        int button1;
                        b1Input = Console.ReadLine();
                        button1 = int.Parse(b1Input);
					
                        //inner if else 
                        if (button1 == 1)
                        {
                            Ninja.hp -= Mav.powerDive;

                        }
                        else if (button1 == 2)
                        {
                            Ninja.hp -= Mav.powerCharge;

                        }
                        else if (button1 == 3)
                        {
                            Ninja.hp -= Mav.wildStrike;

                        }
                        else if (button1 == 4)
                        {
                           Ninja.hp -= Mav.renegade;
                        }
                        else if (button1 == 5)
                        {
                            Ninja.hp -= Mav.shiningStars;
                        }
                        
                        break;
						
					//magic attacks
                    case 'r':
					/*
                        Console.WriteLine("Press 1 for Light");
                        Console.WriteLine("Press 2 for Flame");
                        Console.WriteLine("Press 3 for Snow");
					*/

                        string b2Input;
                        int button2;
                        b2Input = Console.ReadLine();
                        button2 = int.Parse(b2Input);
                     
                        //inner if else
                        if (button2 == 1)
                        {
                            Mav.hp += Mav.lightSpell;
                            
                        }
                        else if (button2 == 2)
                        {
                            Ninja.hp -= Mav.flame;
                        }
                        else if (button2 == 3)
                        {
                            Ninja.hp -= Mav.snow;
                        }
                        
                        break;

                    case 'i':
                       //use for items

                        string b3Input;
                        int button3;
                        b3Input = Console.ReadLine();
                        button3 = int.Parse(b3Input);
                        
					if(button3 ==1)
						{
							Mav.hp += potion;
						}else if(button3 == 2)
						{
							Mav.hp += elixer;
						}
																	
                        break;

                    case 'd':
                        //use for defense
                        break;

                    case 'c':
                        //charater switch command

                        break;


                }//end of switch for input
			}//end of while loop 

	}
}
2 Likes

I use Debug.Log this will display in a console that can be accessed by double clicking the bottom status bar on unity or SHIFT + CTRL + C.

Put

Debug.Log(“hit”);

in whichever if statment you have the hit in.

Hope that helps. If you want something that would display to the player then I’m not too sure about that, I’m thinking to using the gameobject GUI TEXT.

1 Like

Ok so I put in the Debug.Log(“hit”); in to the game when ever I have an attack and I think that the game is not handleing the input right becuase nothing is happening. Do I have to use the Unity input instead of C#s way of handiling input?

I believe so, in the tutorial I used to learn unity they used GUI Text to display text to the user, so thats what I do to display any text. If there is a better way I wouldnt know it, sorry.

EDIT: Oops I thought you we’re still talking about display text to the user. For button input, most likely you can use,

Input.GetKey(KeyCode.W)

to get a specific keyboard key.

The tutorials use

EDIT > PROJECT SETTINGS > INPUT

to handle keys and inputs.

So does anyone know why this is the first hit for “unity C# printing to player output” if Debug.Log prints to the game designer?

I am working on a game. When I was learning How to make game I saw that a command is used that is “print(”“);”
but in my project when I go to use this command it was not working

Pls Help

Please don’t necro-post / hijack threads on these forums. Create your own threads for your own problems.

Thanks.