Среда, 08 Мая 2024, 10:22

Приветствую Вас Гость

[ Новые сообщения · Игроделы · Правила · Поиск ]
  • Страница 1 из 1
  • 1
Форум игроделов » Движки для разработки игр и сложные системы разработки » Unity » Помогите с Магазином !
Помогите с Магазином !
AdomДата: Четверг, 01 Августа 2013, 16:11 | Сообщение # 1
Печенька!
Сейчас нет на сайте
Я решил сделать простой магазин который пока продает аптечки.Так вот покупать легко но я добавил еще деньги я нажимаю покупку но почему то от 10 денег отнимается 1 рубль я нажимаю еще купить а он не отнимает дальше и у меня до сих пор осталось 9 рублей и ни как не могу понять как сделать это.
Вот скрипты писал сам.
Это скрипт жизни врага тк его убиваешь и получаешь деньги.
Код
using UnityEngine;
using System.Collections;

public class Xp2 : MonoBehaviour {
public Transform Enemy;
public float HP;
public Transform RPG;
public Transform Money;
public Transform XP;
// Use this for initialization
void Start () {
HP = 2;
}
       
// Update is called once per frame
void Update () {
if(HP <0){
HP =0;
}
if(HP < 10){
RPG.GetComponent<RPG>().A = 0;    
}
if(HP <5){
Money.GetComponent<Shop>().Money =10;       
}
Money.GetComponent<Shop>().Money -=1;    
}
void OnTriggerEnter(){
if(GameObject.FindWithTag("Bullet2")){
HP -=10;
}else{    
HP +=0;
}
if(HP == 0){
Destroy(GameObject.FindWithTag("Body"));
}else{
if(HP == 0){
Destroy(gameObject);       
}
}
}
}

А это сам магазин.
Код
using UnityEngine;
using System.Collections;

public class Shop : MonoBehaviour {
public int A;
public Rect AptechkaRect;
public Transform XP;
public int  Money;
// Use this for initialization
void Start () {
}
       
// Update is called once per frame
void Update () {
if(GameObject.FindWithTag("Player")&&Input.GetKeyDown(KeyCode.E)){       
}
}

void OnGUI(){
if(GUI.Button(AptechkaRect,"Aptechka")){
Money +=1;    
if(XP.GetComponent<XP>().CurXP <100 && Money >1){
XP.GetComponent<XP>().CurXP +=1;        
}else{
if(XP.GetComponent<XP>().CurXP ==100&& Money <1){
XP.GetComponent<XP>().CurXP +=0;         
}
}
}
}
void OnTriggerStay(){
if(GameObject.FindWithTag("Player")&&Input.GetKey(KeyCode.E)){    
}
}
}

И вот скрипт Жизней персонажа.
Код
using UnityEngine;
using System.Collections;

public class XP : MonoBehaviour {
public Transform Player;  
public Transform Bullet;  
public float xp = 0;  
public float Health;  
public float CurXP;
// Use this for initialization
void Start () {
xp = 100;
}  
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(){
if(GameObject.FindWithTag("Bullet")){
xp -=1;
CurXP -=0.5f;
if(xp <0){
Destroy(GameObject.FindWithTag("Player"));
}
}
}
void OnGUI(){
GUI.Label(new Rect(10, Screen.height - 40, 120, 20),"HP:"+CurXP+ "/"+Health);
}
}

Добавлено (01.08.2013, 16:11)
---------------------------------------------
Помогите !

Сообщение отредактировал Adom - Четверг, 01 Августа 2013, 14:21
Форум игроделов » Движки для разработки игр и сложные системы разработки » Unity » Помогите с Магазином !
  • Страница 1 из 1
  • 1
Поиск:

Все права сохранены. GcUp.ru © 2008-2024 Рейтинг