Question by
prasanthvel · Sep 22, 2017 at 07:56 AM ·
gameobject3dscript.jumping object
How to control GameObjects by Button and Script
Hi, I'm new to unity. I'm trying to control a cube to jump when I click the button in the screen UI. The script must have the ability to change the object by using a public variable for GameObject.
My code is
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ObjController : MonoBehaviour {
public GameObject obj;
public float speed = 1;
// Use this for initialization
void Start () {
}
public void Jump() {
//GetComponent<Rigidbody>().velocity = Vector3.up * speed; // it must be applied to the
particular Obj, but I don't want to limit the objects
obj.GetComponent<Rigidbody>().velocity = Vector3.up * speed; // is this correct to access the game object anthing that dragged into the box.
}
}
In which way I can achieve it??
question.png
(176.4 kB)
Comment