What is wrong or what is missing
i have an object who swing from left to right or right-left between (-0,3 and 0.3), and what i want to do is when i press any key "space" the object fall to the ground.
using UnityEngine;
using System.Collections;
public class DropBox: MonoBehaviour {
void Update() {
if (Input.GetKeyUp(KeyCode.Space))
GetComponent<blocks>().enabled = true;
if (Input.GetKeyUp(KeyCode.Space))
GetComponent<blocks>().enabled = false;
}
Answer by astrokiiD · Jun 01, 2016 at 11:50 AM
The block_0 is inside an empty object called (blocks). And the component block_0 is connected to the crane, and crane has a script who swing. The block_0 is a prefab.
GetComponent<TYPE>()
gives you a component attached to the same GameObject the script is attached to ( GetComponent<BoxCollider>()
would give you the BoxCollider of the GameObject for example). blocks in this case is the GameObject itself.
Your answer
Follow this Question
Related Questions
How to disable Input Events (OnKeyDown etc.) while editing InputField? 2 Answers
Removing Event from New Input System Not Working! 1 Answer
Key pressdown Input Inconsistent 0 Answers
NumericUpDown input field 1 Answer
Roll a Ball Tutorial issue 0 Answers