SHARE
TWEET

script

a guest Apr 23rd, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class templateScript : MonoBehaviour {
  6.  
  7.  
  8.     public Hero hero;
  9.     private SpriteRenderer spriteRenderer;
  10.     private Animator animator;
  11.     private Rigidbody2D rb;
  12.  
  13.  
  14.     public int health;
  15.     public float speed;
  16.     public float jumpHeight;
  17.    
  18.  
  19.     private float horizontalMovement;
  20.  
  21.     int grounded = 0;
  22.     public int amountJumps;
  23.     private int jumpsLeft;
  24.  
  25.     public LayerMask Ground;
  26.     public Transform groundCheck;
  27.     float groundRadius = 0.2f;
  28.  
  29.  
  30.     void Start () {
  31.  
  32.         spriteRenderer = GetComponent<SpriteRenderer>();
  33.         spriteRenderer.sprite = hero.artwork;
  34.  
  35.         rb = GetComponent<Rigidbody2D>();
  36.  
  37.  
  38.         animator = GetComponent<Animator>();
  39.         animator.runtimeAnimatorController = hero.animatorController;
  40.  
  41.         health = hero.health;
  42.         speed = hero.speed;
  43.         jumpHeight = hero.jumpHeight;
  44.  
  45.         amountJumps = hero.amountJumps;
  46.         jumpsLeft = amountJumps;
  47.        
  48.  
  49.     }
  50.  
  51.     public void Update()
  52.     {
  53.         horizontalMovement = Input.GetAxisRaw("Horizontal");
  54.         //Takes the horizontal input to make the character move in void FixedUpdate()
  55.  
  56.  
  57.         if (Input.GetKeyDown(KeyCode.Space))
  58.         {
  59.             rb.velocity = Vector2.up * jumpHeight * grounded;
  60.         }else
  61.         {
  62.             rb.velocity = Vector2.zero;
  63.         }
  64.  
  65.  
  66.     }
  67.  
  68.     public void FixedUpdate()
  69.     {
  70.  
  71.         if (horizontalMovement < 0)
  72.         {
  73.             transform.localScale = new Vector3(-1, transform.localScale.y, transform.localScale.z);
  74.         }
  75.         else if (horizontalMovement > 0)
  76.         {
  77.             transform.localScale = new Vector3(1, transform.localScale.y, transform.localScale.z);
  78.         }
  79.         //Makes the character flip accordingly
  80.  
  81.  
  82.         rb.velocity = new Vector2(horizontalMovement * speed, rb.velocity.y);
  83.  
  84.  
  85.     }
  86.  
  87.  
  88.     #region setting grounded
  89.  
  90.     void OnCollisionEnter(Collision theCollision)
  91.     {
  92.         if (theCollision.gameObject.tag == "Ground")
  93.         {
  94.             grounded = 1;
  95.         }
  96.     }
  97.  
  98.  
  99.     void OnCollisionExit(Collision theCollision)
  100.     {
  101.         if (theCollision.gameObject.tag == "Ground")
  102.         {
  103.             grounded = 0;
  104.         }
  105.     }
  106.  
  107.     #endregion
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top