Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerController : MonoBehaviour {
- Rigidbody rb;
- // Use this for initialization
- void Start () {
- rb = GetComponent<Rigidbody> ();
- }
- // Press Ctrl + '
- // Update is called once per frame
- void Update () {
- float verticalForce = Input.GetAxis("Vertical");
- float horizontalForce = Input.GetAxis("Horizontal");
- Vector3 force = new Vector3 (horizontalForce, 0.0f, verticalForce);
- rb.AddForce (force * 25);
- if (Input.GetKeyDown(KeyCode.Space))
- {
- var renderer = gameObject.GetComponent<Renderer> ();
- //bool isEnabled = renderer.enabled;
- renderer.enabled = !renderer.enabled;
- }
- }
- private void OnCollisionEnter(Collision collision)
- {
- print ("Hit the object");
- if ( collision.gameObject.name == "Cube" )
- {
- Destroy(collision.gameObject);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement