Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

Hey! Im having a error(im having alot of those today, sorry if you had to deal with my problems) where it says "Vector2 which isnt valid in given context" It would be great if someone could help me with it.

$
0
0
using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerController : MonoBehaviour { public float speed; public float JumpForce; private float moveInput; private Rigidbody2D rb; private bool facingRight = true; private bool isGrounded; public Transform groundCheck; public float checkRadius; public LayerMask whatIsGround; private int extraJumps; public int extraJumpsValue; void Start() { extraJumps = extraJumpsValue; rb = GetComponent(); } void FixedUpdate() { isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround); moveInput = Input.GetAxisRaw("Horizontal"); rb.velocity = new Vector2(moveInput * speed, rb.velocity.y); if (facingRight == false && moveInput == 0) { Flip(); } else if (facingRight == true && moveInput < 0) { Flip(); } } void Update() { if (isGrounded == true) { extraJumps = extraJumpsValue; } if (Input.GetKeyDown(KeyCode.Space) && extraJumps > 0) { rb.velocity = Vector2.up * JumpForce; extraJumps--; }else if (Input.GetKeyDown(KeyCode.Space) && extraJumps == 0 && isGrounded == true) { rb.velocity = Vector2 * JumpForce; } } void Flip() { facingRight = !facingRight; Vector3 Scaler = transform.localScale; Scaler.x *= -1; transform.localScale = Scaler; } }

Viewing all articles
Browse latest Browse all 2891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>