Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Void mouse to Input GetKey - PLS HELP TO BEGINNER

Discussion in 'Scripting' started by latasever8, Apr 27, 2020.

  1. latasever8

    latasever8

    Joined:
    Jun 22, 2019
    Posts:
    16
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PickUp : MonoBehaviour {
    6.     public Transform desi;
    7.     public GameObject ağaç;
    8.  
    9.  
    10.     void OnMouseDown()
    11.     {
    12.         GetComponent<BoxCollider>().enabled = false;
    13.         GetComponent<Rigidbody>().useGravity = false;
    14.         this.transform.position = desi.position;
    15.         this.transform.parent = ağaç.transform;
    16.     }
    17.  
    18.     void OnMouseUp()
    19.     {
    20.         this.transform.parent = null;
    21.     GetComponent<BoxCollider>().enabled = true;
    22.     GetComponent<Rigidbody>().useGravity = true;
    23.     }
    24. }
    Brothers, I need to change void OnMouseDown to Input GetkeyDown.E
    same with OnMouseUp

    can you help me?
    I Tried with "Void Update, if Input"
    but didnt work
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,748
    Post the code you tried
     
    latasever8 likes this.
  3. Dextozz

    Dextozz

    Joined:
    Apr 8, 2018
    Posts:
    488
    Code (CSharp):
    1. public class Pickup : MonoBehaviour
    2. {
    3.     private void Update()
    4.     {
    5.         if(Input.GetKeyDown(KeyCode.E))
    6.         {
    7.             // your previous OnMouseDown code here
    8.         }
    9.         else if(Input.GetKeyUp(KeyCode.E))
    10.         {
    11.             // your previous OnMouseUp code here
    12.         }
    13.     }
    14. }
    This should work. Sorry if there are any syntax errors, I wrote it in a notepad.
     
    latasever8 likes this.
  4. latasever8

    latasever8

    Joined:
    Jun 22, 2019
    Posts:
    16
    Thank you soo much ..