Hi, I've been designing my 2D platform game for a school assignment and I've just started working on character movement, I have requested my teachers help and she only says to go watch youtube, she has no idea how to teach so I fear I will fail this class. if you can help me please help asap, thank you so much
ERRORS
Assets/KnightController.cs(46,8): error CS1501: No overload for method `SetFloat' takes `1' arguments
Assets/KnightController.cs(46,27): error CS1061: Type `string' does not contain a definition for `GetComponent' and no extension method `GetComponent' of type `string' could be found. Are you missing an assembly reference?
CODE
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class KnightController : MonoBehaviour {
//how fast the knight can move
public float topSpeed =10f;
//tell the sprite which way it is pointing
bool facingRight = true;
//get reference to animator
Animator anim;
//not grounded
bool grounded = false;
//transform at knights foot to see if he is touching the ground
public Transform GroundCheck;
//how big the circle is going to be when checking for ground
float groundRadius = 0.2f;
//force of the jump
public float jumpForce = 700f;
//what layer is considered ground
public LayerMask whatIsGround;
void Start()
{
anim = GetComponent();
}
//physics in fixed update
void FixedUpdate()
{
//true or false, did the ground transform hit the ground with the ground radius
grounded = Physics2D.OverlapCircle(GroundCheck.position, groundRadius, whatIsGround);
//tell animator grounded
anim.SetBool("Ground", grounded);
//get how fast moving up or down from Rigidbody
anim.SetFloat("vSpeed". GetComponent().velocity.y);
//get move direction
float move = Input.GetAxis("Horizontal");
//add velocity to the ridgidbody in the move direction * our speed
GetComponent().velocity = new Vector2(move * topSpeed, GetComponent().velocity.y);
anim.SetFloat("Speed", Mathf.Abs(move));
//if we're facing the nevagtive direction and not facing right, flip
if(move > 0 && !facingRight)
flip();
else if(move < 0 && facingRight)
flip();
}
void Update()
{
if(grounded && Input.GetKeyDown(KeyCode.Space))
{
//not on the ground
anim.SetBool("Ground", false);
//Add Jump Force To The Y axis
GetComponent().AddForce(new Vector2(0, jumpForce));
}
}
void flip()
{
//saying we are facing the opposite direction
facingRight = !facingRight;
//get the local scale
Vector3 theScale = transform.localScale;
//flip on x axis
theScale.x *= -1;
//apply to the local scale
transform.localScale = theScale;
}
}
↧