Skip to content

Instantly share code, notes, and snippets.

@mohamedbark
Created October 20, 2018 11:16
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/5b894677d9600352af70403a4cd8875a to your computer and use it in GitHub Desktop.
Save mohamedbark/5b894677d9600352af70403a4cd8875a to your computer and use it in GitHub Desktop.
unity gripper left code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class left_grip : MonoBehaviour
{
public GameObject grip1;
public float mSpeed1;
private Rigidbody rbody1;
private int start_position;
private float input;
private int outerLimit, innerLimit;
// Use this for initialization
void Start()
{
innerLimit = 30;
outerLimit = 0;
mSpeed1 = 10f;
start_position = outerLimit;
//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