Search Unity

scripting fail... help

Discussion in 'Getting Started' started by camilalepemonge, May 2, 2019.

  1. camilalepemonge

    camilalepemonge

    Joined:
    Feb 16, 2019
    Posts:
    2
    while trying to create a character controller for 2d i got the following errors on the script

    using UnityEngine;
    using System.Collections;
    public class wellhullothere : MonoBehaviour
    {
    public float maxSpeed = 10f;
    readonly bool facingRight = true;
    void Start()
    {
    }
    void FixedUpdate()
    {
    float move = Input.GetAxisRaw("Horizontal");
    Rigidbody2D.Velocity = new Vector2(move * maxSpeed, Rigidbody2D.Velocity.y); (error: ´Rigidbody2d doesen´t contain a definition for ´velocity´)
    if (move < 0 && !facingRight)
    Flip ();
    else if (move > 0 && facingRight)
    Flip ();
    }
    private void Flip()
    {
    facingRight = !facingRight; (error: a only reading field cannot be assigned)
    Vector3 theScale = transform.localScale;
    theScale.x *= -1;
    transform.localScale = theScale;
    } }
    anybody can help?
     
  2. Green11001

    Green11001

    Joined:
    Apr 14, 2018
    Posts:
    397
    First of all, it is probably "v"elocity.y without a capital. Second of all, I believe you need to remove the readonly part of the bool.
     
  3. camilalepemonge

    camilalepemonge

    Joined:
    Feb 16, 2019
    Posts:
    2
    welp… i failed
    thank you so much!