Невозможно найти путь....(РЕШЕНО)

Программирование на Юнити.

Невозможно найти путь....(РЕШЕНО)

Сообщение HacKeR 19 янв 2011, 00:08

Помогите. ДУмаю все знаю серию уроков http://www.youtube.com/user/BurgZergArcade ..... Вот сделал я ГУИ потом АИ и застряг на Unity3d Tutorial - Melee Combat 1/3....
Всё делал как на виде. но мне консоль ругается на eh.AddjustCurrentHealth(-10); AddjustCurrentHealth - находится в EnemyHealth но почему то мне пишет что не может найти обьект..... Что делать?
Последний раз редактировалось HacKeR 20 янв 2011, 00:56, всего редактировалось 1 раз.
HacKeR
UNIверсал
 
Сообщения: 360
Зарегистрирован: 12 ноя 2010, 21:14

Re: Невозможно найти путь....

Сообщение Ert Donuell 19 янв 2011, 00:11

Ваши исходники можно глянуть?
Добавить dmitrii.baranov.yumasoft в Skype
Аватара пользователя
Ert Donuell
Старожил
 
Сообщения: 781
Зарегистрирован: 05 июл 2010, 09:50
Откуда: Санкт-Петербург
  • ICQ

Re: Невозможно найти путь....

Сообщение HacKeR 19 янв 2011, 00:21

PlayerAttack
Скрытый текст:
Синтаксис:
Используется csharp
using UnityEngine;
using System.Collections;

public class PlayerAttack : MonoBehaviour {
 public GameObject target;
 public float AttackTimer;
 public float CoolDown;

 // Use this for initialization
 void Start () {
  AttackTimer = 0;
  CoolDown = 2.0f;
 }
 
 // Update is called once per frame
 void Update () {
  if(AttackTimer > 0)
   AttackTimer -=Time.deltaTime;
 
  if&#40;AttackTimer < 0&#41;
   AttackTimer = 0;
 
  if&#40;Input.GetKeyUp&#40;KeyCode.F&#41;&#41; {
   if&#40;AttackTimer == 0&#41; {
   Attack&#40;&#41;;
   AttackTimer = CoolDown;
   
   }
  }
 }
 
 private void Attack&#40;&#41; {
   
  float distance = Vector3.Distance&#40;target.transform.position, transform.position&#41;;
 
  Vector3 dir = &#40;target.transform.position - transform.position&#41;.normalized;
   
  float direction = Vector3.Dot&#40;dir, transform.forward&#41;;
 
  Debug.Log&#40;direction&#41;;
 
  if&#40;distance < 2.5f&#41; {
   if&#40;direction > 0&#41;{
   EnemyHealth eh = &#40;EnemyHealth&#41;target.GetComponent&#40;"EnemyHealth"&#41;;
   eh.AddjustCurrentHealth&#40;-10&#41;;
   
   }
  }
 }
}

EnemyHealth
Скрытый текст:
Синтаксис:
Используется csharp
using UnityEngine;

using System.Collections;



public class EnemyHealth : MonoBehaviour {

        public int MaxHealth = 100;

        public int curHealth = 100;

        public int Health = 100;

        public float Screenwidth;

        // Use this for initialization

        void Start &#40;&#41; {



        }

       

        // Update is called once per frame

        void Update &#40;&#41; {

                AddjustCurrentHealth&#40;0&#41;;

                Screenwidth = Screen.width / 2;

       

               

        }

        void OnGUI&#40;&#41;{

        GUI.Box&#40;new Rect&#40;10, 40, Screenwidth, 20&#41;, curHealth + "/" + MaxHealth&#41;;       

               

        }

       

        public void AddjustCurrentHealth&#40;int adj&#41;{

                curHealth += adj;

                if &#40;curHealth < 0&#41;{

                curHealth = 0;

                }

                if &#40;curHealth > MaxHealth&#41;{

                curHealth = MaxHealth;

                }

                if &#40;MaxHealth < 1&#41;{

                MaxHealth = 1; 

                }

                Screenwidth = &#40;Screen.width / 2&#41; * &#40; curHealth / &#40;float&#41;MaxHealth&#41;;

               

        }

       

       

}



 
HacKeR
UNIверсал
 
Сообщения: 360
Зарегистрирован: 12 ноя 2010, 21:14

Re: Невозможно найти путь....

Сообщение Ert Donuell 19 янв 2011, 00:35

Попробуйте вместо
Синтаксис:
Используется csharp
EnemyHealth eh = (EnemyHealth)target.GetComponent("EnemyHealth");

написать
Синтаксис:
Используется csharp
EnemyHealth eh = (EnemyHealth)target.GetComponent<EnemyHealth>;

или
Синтаксис:
Используется csharp
EnemyHealth eh = (EnemyHealth)target.GetComponent<EnemyHealth>();
Добавить dmitrii.baranov.yumasoft в Skype
Аватара пользователя
Ert Donuell
Старожил
 
Сообщения: 781
Зарегистрирован: 05 июл 2010, 09:50
Откуда: Санкт-Петербург
  • ICQ

Re: Невозможно найти путь....

Сообщение HacKeR 19 янв 2011, 08:51

всёравно вот такая ошибка вылетает....

NullReferenceException: Object reference not set to an instance of an object
PlayerAttack.Attack () (at Assets/Scripts/PlayerAttack.cs:45)
PlayerAttack.Update () (at Assets/Scripts/PlayerAttack.cs:25)
HacKeR
UNIверсал
 
Сообщения: 360
Зарегистрирован: 12 ноя 2010, 21:14

Re: Невозможно найти путь....

Сообщение Ert Donuell 19 янв 2011, 11:22

EnemyHealth

Синтаксис:
Используется csharp
using UnityEngine;
using System.Collections;

public class EnemyHealth : MonoBehaviour {
        public int MaxHealth = 100;
        public int curHealth = 100;
        public int Health = 100;
        public float Screenwidth;
       
        // Use this for initialization
        void Start() {
                Screenwidth = Screen.width / 2;
                if (curHealth > MaxHealth)
                        curHealth = MaxHealth;
                if (MaxHealth < 1)
                        MaxHealth = 1;
        }
       
        // Update is called once per frame
        void Update() {
        }
       
        void OnGUI() {
                GUI.Box(new Rect(10, 40, Screenwidth, 20), curHealth + "/" + MaxHealth);        
        }
       
        public void AddjustCurrentHealth(int adj) {
                curHealth += adj;
                if (curHealth < 0)
                        curHealth = 0;
                Screenwidth = (Screen.width/2)*(curHealth/(float)MaxHealth);
        }
}
Добавить dmitrii.baranov.yumasoft в Skype
Аватара пользователя
Ert Donuell
Старожил
 
Сообщения: 781
Зарегистрирован: 05 июл 2010, 09:50
Откуда: Санкт-Петербург
  • ICQ

Re: Невозможно найти путь....

Сообщение HacKeR 19 янв 2011, 16:22

тот же эффект....
HacKeR
UNIверсал
 
Сообщения: 360
Зарегистрирован: 12 ноя 2010, 21:14

Re: Невозможно найти путь....

Сообщение Ert Donuell 19 янв 2011, 22:35

Тогда так

EnemyHealth

Синтаксис:
Используется csharp
using UnityEngine;
using System.Collections;

public class EnemyHealth : MonoBehaviour {
        public int MaxHealth = 100;
        public int curHealth = 100;
        public int Health = 100;
        public float Screenwidth;
       
        // Use this for initialization
        void Start() {
                Screenwidth = Screen.width / 2;
                if (curHealth > MaxHealth)
                        curHealth = MaxHealth;
                if (MaxHealth < 1)
                        MaxHealth = 1;
        }
       
        // Update is called once per frame
        void Update() {
        }
       
        void OnGUI() {
                GUI.Box(new Rect(10, 40, Screenwidth, 20), curHealth + "/" + MaxHealth);        
        }
       
        void AddjustCurrentHealth(int adj) {
                curHealth += adj;
                if (curHealth < 0)
                        curHealth = 0;
                Screenwidth = (Screen.width/2)*(curHealth/(float)MaxHealth);
        }
}
Добавить dmitrii.baranov.yumasoft в Skype
Аватара пользователя
Ert Donuell
Старожил
 
Сообщения: 781
Зарегистрирован: 05 июл 2010, 09:50
Откуда: Санкт-Петербург
  • ICQ

Re: Невозможно найти путь....

Сообщение HacKeR 19 янв 2011, 23:43

неа.... Даже мне друг скидывал свой проект с этими скриптам - у него пашет, у меня нет....

Юнити переставлял..... Что делать?

Если можете добавьте мня в скайп - haker954
HacKeR
UNIверсал
 
Сообщения: 360
Зарегистрирован: 12 ноя 2010, 21:14


Вернуться в Скрипты

Кто сейчас на конференции

Сейчас этот форум просматривают: Yandex [Bot] и гости: 5