Created
October 20, 2018 11:17
-
-
Save mohamedbark/f4a4df1d4f1d948d07f5ac8ce3ff1826 to your computer and use it in GitHub Desktop.
gripper unity code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class right_grip : MonoBehaviour { | |
public GameObject grip1; | |
public float mSpeed1; | |
private Rigidbody rbody1; | |
private float input; | |
private int start_position,outerLimit,innerLimit; | |
// Use this for initialization | |
void Start () { | |
innerLimit = 26; | |
outerLimit = 0; | |
start_position = outerLimit; | |
mSpeed1 = 10f; | |
//rbody1 = GetComponent<Rigidbody>(); | |
} | |
// Update is called once per frame | |
void Update () { | |
//rbody1.AddForce(0f, 0f, 1 * mSpeed1 * Input.GetAxis("Horizontal") * Time.deltaTime); | |
input = Input.GetAxis("Horizontal"); | |
if (input != 0) | |
{ | |
if (input > 0) | |
{ | |
start_position++; | |
} | |
else if (input < 0) | |
{ | |
start_position--; | |
} | |
if (start_position >= outerLimit && start_position <= innerLimit) | |
{ | |
transform.Translate(-1 * Vector3.back * Input.GetAxis("Horizontal") * Time.deltaTime); | |
} | |
if (start_position > innerLimit) | |
{ | |
start_position = innerLimit; | |
} | |
else if (start_position < outerLimit) | |
{ | |
start_position = outerLimit; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment