+ 1

Проблема с Unity3D C#

Всем привет. Такая проблема. Делаю игру. Смысл игры в том, чтобы ГГ (Главный герой), задевая "больных" NPC вылечивал их и получал за это очки. При спавне NPC изначально "здоровые", спустя рандомное кол-во времени они становятся больными. За очки, которые получает ГГ, можно превращать здоровых NPC во врачей, которые будут помогать ГГ касаться "больных" NPC. Пока я на моменте кода спавна и присвоения состояния NPC. Вообще не в курсах как тут это делается. У меня есть отдельный скрипт спавна NPCSpawn и скрипт состояния NPCState. Мне их надо определённым образом связать (как, я объяснил в описании концепции). Код прикрепляю сюда и у себя в профиле (здесь вмещается не всё). Заранее благодарю. NPCSpawn.cs using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class NPCSpawn : MonoBehaviour { public GameObject[] NPCPrefab; public GameObject NPC; //[SerializeField] // Настройки:

24th Dec 2020, 4:47 PM
Андрей Пермяков
Андрей Пермяков - avatar
13 ответов
0
Try Englisch then i can help you with unity
25th Dec 2020, 12:59 PM
Julian Bents
Julian Bents - avatar
0
Julian Bents , The meaning of the game is that Player, touching the "sick" NPC cured them and got points for it. When spawning, NPCs are initially "healthy", after a random amount of time they become sick. For the points that Player gets, you can turn healthy NPCs into doctors who will help Player touch "sick" NPCs. While I'm at the moment when the spawn and assignment of the state of the NPC. I have NPCSpawn script And NPCState script. I need to link them in a certain way (as I explained in the description of the concept). I attach the code here and in my profile (not everything fits here). Thank you in advance.
26th Dec 2020, 10:30 AM
Андрей Пермяков
Андрей Пермяков - avatar
0
Julian Bents , I think you'll understand my code without my Russian comments) I've made all maximum understandable
26th Dec 2020, 10:32 AM
Андрей Пермяков
Андрей Пермяков - avatar
0
Ok if i understand correctly you just want to link the 2 scripts to each other, so you can get acces to the script from the other script, dont you? If it is wrong pls explain me what do you want to do with both script when they are linked
26th Dec 2020, 11:22 AM
Julian Bents
Julian Bents - avatar
0
Julian Bents , yeah, you understood correctly. Look, I create a NPC and then I wanna it will be "Healthy" and I put NPC in class HealthyNPC from NPCState.cs which has some attributes(speed, model(prefab)). After a random time it turns into a "Sick" and I have to use class SickNPC which has that attributes too.
26th Dec 2020, 11:31 AM
Андрей Пермяков
Андрей Пермяков - avatar
0
You just need to create Instances from the script: public NPC npc; public NPCState state; // to acces the script assign it in the Editor // example to change vars void regenerate health(){ npc.health += 0.5f; }
26th Dec 2020, 11:44 AM
Julian Bents
Julian Bents - avatar
0
Julian Bents could you fix my code on your profile? I don't understand.
26th Dec 2020, 11:54 AM
Андрей Пермяков
Андрей Пермяков - avatar
0
Ok i will do it but is there an npc script
26th Dec 2020, 12:10 PM
Julian Bents
Julian Bents - avatar
0
If you mean its movement, it's absent
26th Dec 2020, 12:12 PM
Андрей Пермяков
Андрей Пермяков - avatar
0
Julian Bents maybe I somehow can send to you all my code files?
26th Dec 2020, 12:14 PM
Андрей Пермяков
Андрей Пермяков - avatar
0
mail, for example?
26th Dec 2020, 12:15 PM
Андрей Пермяков
Андрей Пермяков - avatar
0
Maybe discord
26th Dec 2020, 12:17 PM
Julian Bents
Julian Bents - avatar
0
Yep
26th Dec 2020, 12:17 PM
Андрей Пермяков
Андрей Пермяков - avatar