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 templateScript : MonoBehaviour {
- public Hero hero;
- private SpriteRenderer spriteRenderer;
- private Animator animator;
- private Rigidbody2D rb;
- public int health;
- public float speed;
- public float jumpHeight;
- private float horizontalMovement;
- int grounded = 0;
- public int amountJumps;
- private int jumpsLeft;
- public LayerMask Ground;
- public Transform groundCheck;
- float groundRadius = 0.2f;
- void Start () {
- spriteRenderer = GetComponent<SpriteRenderer>();
- spriteRenderer.sprite = hero.artwork;
- rb = GetComponent<Rigidbody2D>();
- animator = GetComponent<Animator>();
- animator.runtimeAnimatorController = hero.animatorController;
- health = hero.health;
- speed = hero.speed;
- jumpHeight = hero.jumpHeight;
- amountJumps = hero.amountJumps;
- jumpsLeft = amountJumps;
- }
- public void Update()
- {
- horizontalMovement = Input.GetAxisRaw("Horizontal");
- //Takes the horizontal input to make the character move in void FixedUpdate()
- if (Input.GetKeyDown(KeyCode.Space))
- {
- rb.velocity = Vector2.up * jumpHeight * grounded;
- }else
- {
- rb.velocity = Vector2.zero;
- }
- }
- public void FixedUpdate()
- {
- if (horizontalMovement < 0)
- {
- transform.localScale = new Vector3(-1, transform.localScale.y, transform.localScale.z);
- }
- else if (horizontalMovement > 0)
- {
- transform.localScale = new Vector3(1, transform.localScale.y, transform.localScale.z);
- }
- //Makes the character flip accordingly
- rb.velocity = new Vector2(horizontalMovement * speed, rb.velocity.y);
- }
- #region setting grounded
- void OnCollisionEnter(Collision theCollision)
- {
- if (theCollision.gameObject.tag == "Ground")
- {
- grounded = 1;
- }
- }
- void OnCollisionExit(Collision theCollision)
- {
- if (theCollision.gameObject.tag == "Ground")
- {
- grounded = 0;
- }
- }
- #endregion
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement