Created
October 20, 2018 11:16
-
-
Save mohamedbark/5b894677d9600352af70403a4cd8875a to your computer and use it in GitHub Desktop.
unity gripper left 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 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