Advertisement
Wolverine_X-Man

Player.cs

Mar 6th, 2021
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.95 KB | None | 0 0
  1. using System;
  2. using UnityEngine;
  3.  
  4. public class Player : MonoBehaviour
  5. {
  6.  
  7.     [SerializeField] private float speed;
  8.     [SerializeField] private float horizontalInput;
  9.     [SerializeField] private float verticalInput;
  10.    
  11.     /*
  12.     private void OnCollisionEnter(Collision other)
  13.     {
  14.         throw new NotImplementedException();
  15.     }
  16.     */
  17.  
  18.     private void OnTriggerEnter(Collider other)
  19.     {
  20.         if (other.CompareTag("Diamond"))
  21.         {
  22.             speed++;
  23.             print("Diamond Collected");
  24.             Destroy(other.gameObject);
  25.         }
  26.     }
  27.  
  28.     void Update()
  29.     {
  30.         Controls();
  31.     }
  32.  
  33.     private void Controls()
  34.     {
  35.         horizontalInput = Input.GetAxis("Horizontal");
  36.         verticalInput = Input.GetAxis("Vertical");
  37.         //  new vector3(-1,0,0) * 5 * real time
  38.         transform.Translate(new Vector3(horizontalInput,0,verticalInput) * speed * Time.deltaTime);
  39.     }
  40. }
  41.  
  42. /* Thankyou Baccho */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement