Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

problem when clicking on Button

Discussion in 'Scripting' started by Trild123787898, Jan 20, 2020.

  1. Trild123787898

    Trild123787898

    Joined:
    Dec 9, 2018
    Posts:
    206
    When I click on the Button, the object turns around, but when I have to release the Button, the object is left to stand still, the problem is that I don’t know what to write in
    TwoTaskOnClick () so that it doesn't rotate?
    Victorist Event Trigger, OnPointerDown (TaskOnClick), OnPointerUp (TwoTaskOnClick)

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using UnityEngine.EventSystems;
    6.  
    7.  
    8. public class mehanic : MonoBehaviour
    9. {
    10.     public Transform detail1;
    11.     public Transform detail2;
    12.     public Transform detail3;
    13.  
    14.     private bool click;
    15.  
    16.  
    17.     void Start()
    18.     {
    19.        
    20.     }
    21.  
    22.  
    23.     public  void TaskOnClick()
    24.     {
    25.         click = true;
    26.  
    27.     }
    28.  
    29.     public void TwoTaskOnClick()
    30.  
    31.     {
    32.        
    33.     }
    34.     void FixedUpdate()
    35.     {
    36.         if (click == true)
    37.         {
    38.             detail1.localRotation = Quaternion.RotateTowards(detail1.localRotation, Quaternion.Euler(new Vector3(30, 0, 0)), 20f * Time.deltaTime);
    39.         }
    40.     }
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,186
    If FixedUpdate is rotating it when click is true...then, logically setting click to false would stop it.
     
    Trild123787898 likes this.
  3. Trild123787898

    Trild123787898

    Joined:
    Dec 9, 2018
    Posts:
    206
    thanks for the logical explanation, something I seriously stepped