Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class controlls : MonoBehaviour {
- public GameObject character;
- public GameObject cube;
- private CharacterController controller;
- public Vector3 pushingVector = new Vector3 (0,0,0); // Z axis must be negative.
- public Vector3 enclosingVector = new Vector3 (0,0,0); // Z axis must be cube Z axis - atleast 0,1
- public Vector3 leftAddingVector = new Vector3 (0,0,0); // add negative X, AND LEAVE THE Y AND THE Z AXIS TO 0
- public Vector3 rightAddingVector = new Vector3 (0,0,0); // add possitive X, AND LEAVE THE Y AND THE Z AXIS TO 0
- public Vector3 heigthAddingVector = new Vector3 (0,0,0); // add possitive Y, AND LEAVE THE X AND Z TO 0
- public float pushingSmootness;
- private bool isCollided = false;
- // Use this for initialization
- void Start () {
- controller = GetComponent<CharacterController>();
- }
- // Update is called once per frame
- void FixedUpdate () {
- push ();
- if (Input.GetMouseButtonDown (0)) {
- enclose();
- leftUp();
- }
- }
- private void enclose () {
- if (character.collider.bounds.Contains (cube.transform.position)) {
- isCollided = true;
- } else {
- isCollided = false;
- }
- while (isCollided==false) {
- character.transform.position = Vector3.Lerp (character.transform.position,enclosingVector, 2);
- }
- }
- private void leftUp () {
- character.transform.position = Vector3.Lerp (character.transform.position, character.transform.position + leftAddingVector, 2);
- character.transform.position = Vector3.Lerp (character.transform.position, character.transform.position + heigthAddingVector, 2);
- }
- private void push(){
- character.transform.position = Vector3.Lerp (character.transform.position, character.transform.position + pushingVector, pushingSmootness * Time.deltaTime);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement