- Home /
GUI text like GTA
Hello Everyone! Im new in unity3d and currently working hard for my thesis about 3d vle implementation in our school. I can i pick up an object and then it it gives me amount of points in the other hand the points are displayed in GUI text. Just like in GTA: Vice City that if Tommy picks up money it adds value to the gui text intended for current money. Please help its for my thesis purpose and i am working very hard for it.
Answer by Ziad · Jul 16, 2011 at 07:16 PM
Well, Here is a script i made it may help u, put this script on ur money or whatever u want to pick up
using UnityEngine; using System.Collections;
public class PickUps : MonoBehaviour {
 public Transform Player;
 void Start()
 {
     GameObject Plr;
     Plr = GameObject.Find("Write Ur Character Name Here");
     Player = Plr.transform;
 }
 
 void Update()
 {
     if (Score.Instance.ScorePointsLeft == 0)
         return;
     PickUpWhileTouched();
 }
 void PickUpWhileTouched()
 {
     if (Vector3.Distance(transform.position, UrCharacterName.position) <= 1)
     {
         Score.Instance.ScorePoints += 80;
         Score.Instance.ScorePointsLeft -= 80;
         GameObject.Destroy(gameObject);
     }
 }
}
and put this script on ur player character
using UnityEngine; using System.Collections;
public class Score : MonoBehaviour {
 public GUIStyle mySkin;
 public static Score Instance;
 public Texture2D Win;
 public int ScorePoints = 0;
 public int ScorePointsLeft = 4000;
 void Awake ()
 {
     Instance = this;
 }
 
 void Update ()
 {
 
 }
 public void OnGUI()
 {
     DisplayScore();
     DisplayWin();
 }
 public void DisplayScore()
 {
     GUI.Label(new Rect(10, 10, 100, 20), "Points: " + ScorePoints.ToString());
     GUI.Label(new Rect(10, 30, 300, 20), "Points: " + ScorePointsLeft.ToString());
 }
 public void DisplayWin()
 {
     if (ScorePointsLeft == 0)
     {
         GUI.Label(new Rect(50, 50, 1000, 500), Win);
     }
 }
}
and thats all,.... u should play with the script untile u get what u want,
Hello there thanks Ziad for the code i really appreciate it! Im just wondering if it the score will cumulatively add in the gui text if for example i pick up 5 items?
When u pick up something the score increace by 80 as i wrote in the script :) and add me if u need more info ziad_khalid@yahoo.com
I got the logic thanks! but i jUSt tried and theres an error saying "Assets/zscripts universal/Pickup.cs(18,9): error CS0103: The name `Score' does not exist in the current context " do you encounter that error? Ill add you up later my friend in Yahoo messenger, i just have trouble logging in my account.
U Should name the first script as (PickUps) in ur project tap and the second as (Score) and that should fix the problem
Answer by franksmith36 · Apr 12, 2012 at 03:16 PM
First script as pickups is required in your project. I always use such script in my thesis writing management tools.
Your answer
 
 
             Follow this Question
Related Questions
gameObject.enabled is not working 1 Answer
activate gui on trigger enter 1 Answer
Coin pickup script not working..? 1 Answer
Trigger collision with Player won't work 2 Answers
Mission Objectives 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                