Search Unity

Cant add behavior script to sprite

Discussion in '2D' started by GDNova, Sep 17, 2014.

  1. GDNova

    GDNova

    Joined:
    Sep 17, 2014
    Posts:
    1
    I have the flowing behavior scrip that i made, but am unable to add it to my sprite. can someone please tell me why?

    using UnityEngine;
    using System.Collections;

    public class newBehaviourScript1 : MonoBehaviour {

    public float movemnetSpeed1 = 5.0f;
    private int jumpHeight1 = 500;

    void start(){
    }

    void update (){


    if (Input.GetKey ("left") || Input.GetKey ("a")) {
    transform.position -= Vector3.right * movemnetSpeed1 * Time.deltaTime;
    transform.eulerAngles = new Vector2(0, 180);
    }
    if (Input.GetKey ("right") || Input.GetKey ("d")) {
    transform.position += Vector3.right * movemnetSpeed1 * Time.deltaTime;
    transform.eulerAngles = new Vector2(0, 0);
    }
    if (Input.GetButtonDown ("jump") || Input.GetKey ("w")) {
    jump();
    }
    }

    void jump(){
    rigidbody2D.AddForce(new Vector3.up(0, jumpHeight1), ForceMode2D.Force);

    }
    }

    the sprite has a rigidbody 2d enabled,and it is not kinematic. As well as a 2D box collider

    By the way, I am very new to unity, and c# in general so if you could make your answer as simple as possible I would appreciate it greatly
     
  2. Limeoats

    Limeoats

    Joined:
    Aug 6, 2014
    Posts:
    104
    When you say you can't add it to the sprite, what exactly do you mean? What error are you getting?
    Add the script to the sprite by selecting the sprite, clicking "Add Component", and navigating to your script. Once you choose the script, it should be attached to your sprite.
     
  3. Limeoats

    Limeoats

    Joined:
    Aug 6, 2014
    Posts:
    104