Skip to content

Instantly share code, notes, and snippets.

@mohamedbark
Created October 20, 2018 11:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohamedbark/f4a4df1d4f1d948d07f5ac8ce3ff1826 to your computer and use it in GitHub Desktop.
Save mohamedbark/f4a4df1d4f1d948d07f5ac8ce3ff1826 to your computer and use it in GitHub Desktop.
gripper unity code
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