#lets make a thread, and send both script
1 messages · Page 1 of 1 (latest)
I will change the .name.equals player later
i just want the white square system to work
which object has which script btw
also not very good doing this in update cs void Update() { currentHeldRedSquare.transform.localPosition = Vector3.zero; }
every red square has their own GrabScript and every white square has a blockplacescript
just parent it
looks like both updates are overwriting values of one transform
well i want the transform position to be equal to the grabposition if it is being picked up
and i want the transform position to be equal to the white square
position if it touches the white square
yes but you can just use the lines i sent
it should work
make sure that method is running
which lines
public class WhiteSquare : MonoBehaviour
{
private RedSquare currentHeldRedSquare;
public void TrySetHeld(RedSquare sq)
{
if (currentHeldRedSquare!= null) return;
currentHeldRedSquare= sq;
}
}
public class RedSquare : MonoBehaviour
{
public void OnTriggerEnter2D(Collider2D other)
{
if (other.TryGetComponent(out WhiteSquare white))
{
white.TrySetHeld(this);
}
}
}
these?
public void TrySetHeld(RedSquare sq)
{
Debug.Log("Trying to set square" + sq.name);
if (CurrentHeldRedSquare != null) return;
CurrentHeldRedSquare = sq;
CurrentHeldRedSquare.transform.position = transform.position;
}```
public void TrySetHeld(GrabScript sq)
{
Debug.Log("Trying to set square" + sq.name);
if (currentHeldRedSquare != null) return;
currentHeldRedSquare = sq;
currentHeldRedSquare.transform.position = transform.position;
}
modification is good or no?
put another at bottom just for good measure
yes
get rid of that line of Update
if currentHeldSquare was null you get spammed with error
im gonna look what happens
Well what happens is
the picking up and placing still works
when i hover over a white square with the red square it says its added the square but it didnt actually move it because i have it on my grabposition
i need to release the block first i think
@summer isle ok im making good progress
yeah good thought
by making it so it releases the block using the Release() function i make it go into the white square
the other one was cluttered i didnt noticed it was overwritten
yes because you still need to clean it up
now that BlockPlaceScript has its own method to Try to place down
now you need same thing for retrieval
in the blockplacescript or the grabscript?
no
using e to pick it up like normal
that works fine, but the whitesquare still thinks it has a block inside
but what determines that you are able to pickup
when it hasnt
iknow what the problem is
but how do you find that particular red square
if it triggers
PickupAllowed will be true if the block is touching the player and if the player is not holding anything
ahh this is on the red square?
yes
you should have a slot on the player to check
what do you mean?
but also you need a way to tell the whitesquare that you got picked up
GrabScript is the red square?
yes
eh confusing naming scheme also red square does wayy too much
this should only be in the player
Yeah, that was my bad
but anyway if player had GrabScript redSquare slot for example
so you can actually determine the thing you're holding if its null or not
what you can do is make a slot for whitesquare in red square maybe
thats one way to do it
private BlockPlaceScript currentParent;
like
private BlockPlaceScript whiteSquare;
yea
ok
So Retrieve(); or something
so the whitesquare script will set the currentredsquare to null
public void TrySetHeld(GrabScript sq)
{
if (currentHeldRedSquare!= null) return;
currentHeldRedSquare= sq;
currentHeldRedSquare.SetWhiteSquare(this)
}
then you can call that same method but set it to Null on pickup
private void PickUp()
{
movementScript.holding = true;
holding = true;
if(whiteSquare != null) whiteSquare.SetWhiteSquare(null);
}```
public void SetWhiteSquare(BlockPlaceScript ws)
{
if (whiteSquare = null) return;
whiteSquare = null;
}
i did this, but i think its way wrong
should the SetWhiteSquare() be in the whitesquare script or the red square
but the pickupscript is already in the redsquare
private void PickUp()
{
movementScript.holding = true;
holding = true;
if(whiteSquare != null) whiteSquare.SetWhiteSquare(null);
}
this one
wait yeah
and the whiteSquare.SetWhiteSquare should be in the white script then, but how do i make it in the red square
sorry about that
It was first just a test on picking up blocks, then i wanted to expand and add these white things
alr
Update: I have been able to make the blocks go into the white squares as i wanted to
i have also been able to make it so i can pick up the block, but now there is the issue again where i can place multiple blocks in one white square
So i am going to try and fix that now
This one is in the Redsquare script
this one in the white square script
This one is also in the red square script
send updated scripts in link
why did you add this
currentHeldRedSquare.Release(); inside TrySetHeld
So the player releases the block, if the block isnt released it will just be held by the player
by making position equal to grabposition
because your placing script is not checking for slot
if (currentHeldRedSquare != null) return; this would keep anything below to run if you try to place block on white that has red
your must've override or done something to do so somewhere
im confused sorry
i have done some tests
and sometimes it just does the things below cs if (currentHeldRedSquare != null) return; even if currentHeldSquare != null
you have to find out why currentHeldSquare is null for some reason
no but it isnt, because i have a public bool in game so i can see if it is null or not
and when i do the test it says it isnt null
then something else is placing it there instead of that method
prob your old code part
i tried to send a video
of what i mean
you dont have to download it if you dont want to
should i make another yt link?
has to be mp4 to work on DC
hmm I see
void Update()
{
if(currentHeldRedSquare != null)
{
holding = true;
}
else
{
holding = false;
}
}
how many blockplace into 1?
I see 2 nested blocplace
sorry?
maybe there is another script on parent ?
no
the empty gameobject just has a transform
The debug.log shouldnt say Added if the holding is true
cus if the holding is true that means that currentHeldRedSquare != null
yeah
public void TrySetHeld(GrabScript sq)
{
Debug.Log("Trying to set square" + sq.name);
if (currentHeldRedSquare != null) return;
currentHeldRedSquare = sq;
currentHeldRedSquare.Release();
currentHeldRedSquare.transform.position = transform.position;
Debug.Log($"Added {sq.name}!");
}
and then it just returns
something obvious im not noticing
Actual Question: Do you find it fun to help me with my project?
prob because im at work haha
I enjoy helping where I can sure
in spare time
cool
im just at work but I get out in a half hr so ill be fully focus mode haha
1Pm here
lol
it prob has to do with there being more than 1 white squares
or no?
what if i say whiteSquare = null when i pickup
private void PickUp()
{
movementScript.holding = true;
holding = true;
if (whiteSquare != null)
{
whiteSquare.ClearWhiteSquare();
whiteSquare = null;
}
}
i added the Whitesquare = null line
Omg
it almost works perfectly
on some weird moments it still takes 2 blocks in one white square
What if i just continue with my game idea with this just being a bug that i can fix later
or should i really fix it now?
should fix it now
Im stuck
im gonna fix it later and im gonna take a break
Thanks a lot for the help today, i really appreciate it!
no problem Ill try to send some ideas how to fix in a bit