Advertisement
Guest User

Untitled

a guest
Nov 21st, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class controlls : MonoBehaviour {
  5.  
  6. public GameObject character;
  7. public GameObject cube;
  8. private CharacterController controller;
  9. public Vector3 pushingVector = new Vector3 (0,0,0); // Z axis must be negative.
  10. public Vector3 enclosingVector = new Vector3 (0,0,0); // Z axis must be cube Z axis - atleast 0,1
  11. public Vector3 leftAddingVector = new Vector3 (0,0,0); // add negative X, AND LEAVE THE Y AND THE Z AXIS TO 0
  12. public Vector3 rightAddingVector = new Vector3 (0,0,0); // add possitive X, AND LEAVE THE Y AND THE Z AXIS TO 0
  13. public Vector3 heigthAddingVector = new Vector3 (0,0,0); // add possitive Y, AND LEAVE THE X AND Z TO 0
  14. public float pushingSmootness;
  15. private bool isCollided = false;
  16.  
  17.  
  18. // Use this for initialization
  19. void Start () {
  20. controller = GetComponent<CharacterController>();
  21. }
  22.  
  23. // Update is called once per frame
  24. void FixedUpdate () {
  25. push ();
  26. if (Input.GetMouseButtonDown (0)) {
  27. enclose();
  28. leftUp();
  29. }
  30. }
  31.  
  32. private void enclose () {
  33. if (character.collider.bounds.Contains (cube.transform.position)) {
  34. isCollided = true;
  35. } else {
  36. isCollided = false;
  37. }
  38. while (isCollided==false) {
  39. character.transform.position = Vector3.Lerp (character.transform.position,enclosingVector, 2);
  40. }
  41.  
  42. }
  43.  
  44. private void leftUp () {
  45. character.transform.position = Vector3.Lerp (character.transform.position, character.transform.position + leftAddingVector, 2);
  46. character.transform.position = Vector3.Lerp (character.transform.position, character.transform.position + heigthAddingVector, 2);
  47. }
  48.  
  49. private void push(){
  50. character.transform.position = Vector3.Lerp (character.transform.position, character.transform.position + pushingVector, pushingSmootness * Time.deltaTime);
  51. }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement