static void Predicted(Obj_AI_Base unit)
{
float time;
float sintime;
float stop = 0f;
Vector3 InterPos = default(Vector3);
Vector3 movevec = default(Vector3);
Vector3 EndInterPos = default(Vector3);
float xminus;
float yminus;
float d;
time = 0.3f + ObjectManager.Player.Distance(unit)/1000;
sintime = unit.MoveSpeed * time;
Chat.Print(time+" "+stop+" "+sintime+" "+InterPos+" "+movevec);
if (Game.Time * 1000 > stop + 13f)
{
Chat.Print("lol");
InterPos.X = unit.Position.X;
InterPos.Y = unit.Position.Y;
movevec.X = unit.Path.LastOrDefault().X;
movevec.Y = unit.Path.LastOrDefault().Y;
stop = Game.Time * 1000;
}
if (Game.Time * 1000 > stop + 10f && Game.Time * 1000 < stop + 14f)
{
Chat.Print("lol2");
}
}
Nie przypisuje wartości do InterPos, movevec, stop. Wyświetla napis "lol", stop = "0", time i sintime oblicza normalnie dla interpos i movevec x=0, y=0, z=0. Napisu "lol2" już nie wyświetla bo stop cały czas jest 0.
Jeśli nie przypisze wartości na początku do zmiennych to błąd, mogę też bez przypisania zrobić np. float stop = new float() ale też nie działa i nie przypisuje do stop Game.Time * 1000:
error CS0165: Use of unassigned local variable 'stop'
error CS0170: Use of possibly unassigned field 'X'
error CS0170: Use of possibly unassigned field 'Y'
Gdy deklaruje zmienne stop, movevec, interpos jako globalne statyczne to wszystko działa ale ja potrzebuje tej metody dla wielu obiektów a przy zmiennej globalnej dla wszystkich obiektów oblicza te same wartości mimo różnych pozycji.