- Home /
how to change Font size, Type and position of this code? (C#)
please help i don't know much about code and a friend made this, i only need to change the text parameters.
script component to click an obj
using UnityEngine;
using System.Collections;
public class Character : MonoBehaviour
{
public string myWords = string.Empty;
private void Start ()
{
}
private void Update ()
{
}
public string GetWords ()
{
return myWords;
}
}
script component for the main camera!
using UnityEngine;
using System.Collections;
public class UI_Demo : MonoBehaviour
{
private GameObject clicked = null;
private void Start()
{
}
private void Update ()
{
if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;
if (Physics.Raycast(Camera.mainCamera.ScreenPointToRay(Input.mousePosition), out hit))
{
if (hit.collider.gameObject.GetComponent<Character>() != null)
clicked = hit.collider.gameObject;
else
clicked = null;
}
else
clicked = null;
}
}
private void OnGUI()
{
if (clicked != null)
GUI.Label(new Rect(15,15,200,25), clicked.GetComponent<Character>().GetWords());
}
}
please help!!
Answer by VioKyma · Aug 02, 2013 at 02:36 AM
All of the display code (for the text) is in the OnGUI() function.
If you want to change position, the part you want to change is on line 33:
new Rect(15,15,200,25)
where each parameter specifies: x position, y position, width, height.
To change the font size and type, it is probably easiest to create a skin within the Unity editor, then you just need to use (before line 33 or in Start()):
GUI.skin = skin;
And in the declarations:
public GUISkin skin;
then you can select the skin from the object properties within the Unity editor.
To find out how to use Skins, check out this link:
http://docs.unity3d.com/Documentation/Components/class-GUISkin.html
omg ty very much! i was having trouble but now i rememberer that the text shown is a Label ty Vio$$anonymous$$yma it work'd! ♥
Note, if you want, you can also use a GUIStyle to set the style just for Label if that is easier. But, later your GUISkin can be configured for other controls, so I recommend this for most situations unless you will only be using Labels.
Is there a straight forward method to increase font size!?! I noticed I can be creative with backgrounds and such but nothing to increase the size of fonts! Thanks!
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
problem with my simple script please help. 2 Answers
Official Unity Space Shooter Tutorial 1 Answer
Manipulate gameobjects, pick up & rotate 0 Answers
Custom Physics? 2 Answers