How to change unit during testing pathnode (unity turn based strat)

Hello.
In testing script we define the 0,0 position.
So if we move the default unit and still testing the path, the test still start from 0,0 not from the unit.
Normal.
If I replace
GridPosition startGridPosition = new GridPosition (0,0)
by
GridPosition startGridPosition = unit.GetGridPosition();
And in my unit field in unity I’ve placed the first Unit in the scene, when I move my unit, and press T, the drawing lines start from the new unit position.
Cool.
But If I select the other unit, the drawing lines start from the first unit position.
Normal it’s the one we have put in the unit field in unity in the testing Game Object.
So i would want to draw the line from the current selected Unit.
My idea was to create a

private UnitActionSystem unitActionSystem;

to reach the method GetSelectedUnit and transform the code in :

GridPosition startGridPosition =unitActionSystem.GetSelectedUnit().GetGridPosition();

But when I launch the game, select the other unit and press T I’ve a error message with missing element.
For me write unitActionSystem.GetSelectedUnit is equal to write unit because it returns unit.
And after I try to reach the GetGridPosition.
I’ve no error message in Visual studio.
So where is my mistake please?
Thanks.
François

Did you set unitActionSystem to anything? You made it private, but I’m not sure if you made it serializable in the inspector, so i don’t know if you dragged anything into the field. I also don’t know if you did a FindObjectOfType<UnitActionSystem>(). Only thing I can think of, based on the info we have, is that UnitActionSystem has not been set to anything and is therefore null

Can you paste the specifics of the error message (that info at the bottom of the console when you click on the error message, along with the script it refers to?

Hey !
it was that.
I haden’t serialized the UnitActionSystem in the testing script :slight_smile:
It works now perfectly.
Changing unit and pressing T make start the draw from the selected unit where it is :slight_smile:

Thanks a lot my friends :slight_smile:
Have a nice day.
François

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms