Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Player position doesn't change on mouse click

Henrique_S_RHenrique_S_R Member
edited June 2020 in Programming

I have made a simple script for a ladder object which means when I click on the ladder, the players position should change to the topOfLadder position but the mouse click is registering but the position of the player doesn't change to the topOfLadder position. The script is placed on the ladder object. What am I doing wrong?


This is the script:

using System.Collections;

using System.Collections.Generic;

using System.Diagnostics;

using UnityEngine;


public class GoUpLadder : MonoBehaviour

{

  public Transform topOfLadder;

  public Transform bottomOfLadder;

  public Transform player;

  public bool climbedUp = false;


  // Start is called before the first frame update

  void Start()

  {

     

  }


  // Update is called once per frame

  void Update()

  {

     

  }


  void OnMouseOver()

  {

    if (Input.GetMouseButtonDown(0) && climbedUp == false)

    {

      UnityEngine.Debug.Log("Climbed Up!");

      player.position = topOfLadder.position;

      climbedUp = true;

    }

    else if (Input.GetMouseButtonDown(0) && climbedUp == true)

    {

      UnityEngine.Debug.Log("Climbed Down!");

      player.position = bottomOfLadder.position;

      climbedUp = false;

    }

  }

}

Best Answer

  • Henrique_S_RHenrique_S_R Member
    Accepted Answer

    Never mind, I fixed it. Just had to check Auto Sync Transforms in Project Settings

Sign In or Register to comment.