Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerController : MonoBehaviour {
  6.  
  7. Rigidbody rb;
  8.  
  9. // Use this for initialization
  10. void Start () {
  11. rb = GetComponent<Rigidbody> ();
  12. }
  13.  
  14. // Press Ctrl + '
  15. // Update is called once per frame
  16. void Update () {
  17. float verticalForce = Input.GetAxis("Vertical");
  18. float horizontalForce = Input.GetAxis("Horizontal");
  19.  
  20. Vector3 force = new Vector3 (horizontalForce, 0.0f, verticalForce);
  21. rb.AddForce (force * 25);
  22.  
  23. if (Input.GetKeyDown(KeyCode.Space))
  24. {
  25. var renderer = gameObject.GetComponent<Renderer> ();
  26. //bool isEnabled = renderer.enabled;
  27. renderer.enabled = !renderer.enabled;
  28. }
  29. }
  30.  
  31. private void OnCollisionEnter(Collision collision)
  32. {
  33. print ("Hit the object");
  34. if ( collision.gameObject.name == "Cube" )
  35. {
  36. Destroy(collision.gameObject);
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement