Question by
mackers7718 · May 01, 2017 at 02:27 PM ·
c#character movement
Need my fish character to move up and down, not just left and right.
using UnityEngine; using System.Collections; using UnityEngine.UI; public class CONTROLLER : MonoBehaviour {
public Rigidbody2D thisRigidbody;
public float speed = 5;
public float jumpSpeed = 5;
private bool grounded = true;
public int Hero_Score = 0;
public Text scoreText;
// Use this for initialization
void Start() { }
// Update is called once per frame
void Update() { }
void FixedUpdate()
{
var move = new Vector3(Input.GetAxis("Horizontal"), 0, 0);
transform.position += move * speed * Time.deltaTime;
if (Input.GetKey(KeyCode.UpArrow) && grounded == true)
{
grounded = false;
thisRigidbody.velocity = new Vector3(0, jumpSpeed, 0);
}
}
void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.tag == "BLOCK") {
grounded = true;
}
if (col.gameObject.tag == "ITEM") {
//Add Score
Destroy (col.gameObject);
Hero_Score += 1;
scoreText.text = "Keys:" + Hero_Score.ToString ();
}
if (col.gameObject.tag == "end") {
Application.LoadLevel ("WINNER SCREEN");
}
if (col.gameObject.tag == "enemy") {
Application.LoadLevel ("lost_screen");
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612120929im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do i calculate in which direction my character is moving relative to it's rotation? 0 Answers
How do i calculate in which direction my character is moving relative to it's rotation? 0 Answers
Issues with making a climbing script compatible with CharacterController 0 Answers
Trying to figure out WallRiding, with Vector3.Cross 0 Answers
Character flies up and gets stuck there, won't move forward? 1 Answer