Hello, I am stuck.
My script was used to transport an item to the player holder location.
Since I made the player in Prefab as well as the said object, the object in question takes the starting position rather than the updated position of the player.
Can someone please help me?
public GameObject player;
GameObject holder;
private bool isStick = false;
Rigidbody2D rb;
private bool isStoping = false;
Vector2 holderPosition;
void Start()
{
rb = GetComponent<Rigidbody2D>();
holder = player.transform.Find("holder").gameObject;
}
private void Update()
{
holder = player.transform.Find("holder").gameObject;
holderPosition = new Vector2(holder.transform.position.x, holder.transform.position.y);
}
private void FixedUpdate()
{
if (isStick == true && PlayerController.grabMode == true && PlayerController.carrying == 1)
{
transform.position = holderPosition;
rb.velocity = new Vector3(0, 0, 0);
rb.velocity = Vector2.zero;
GetComponent<CapsuleCollider2D>().enabled = false;
PlayerController.isCarrying = true;
}