using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class moveplayer : MonoBehaviour
{
Animator anim;
Rigidbody2D rb;
public GameObject leftbtn ;
public GameObject rightbtn;
public GameObject jumpbtn ;
float posJumpBtn;
float posbtnright;
float posbtnleft;
float run;
bool whenlook ;
void Start()
{
posbtnright = rightbtn.transform.position.y;
posbtnleft = leftbtn.transform.position.y;
posJumpBtn = jumpbtn.transform.position.y;
rb = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
void Update()
{ if (posJumpBtn != jumpbtn.transform.position.y){
rb.AddForce (transform.up * 350f , ForceMode2D.Impulse);
}
if(posbtnleft != leftbtn.transform.position.y){
run = -600f;
whenlook = false ;
Flip();
}
else if(posbtnright != rightbtn.transform.position.y){
run = 600f ;
whenlook = true;
Flip();
}
else { run = 0f;
}
rb.velocity = new Vector2 (run,rb.velocity.y);
}
void Flip(){
if(whenlook == false){
transform.localRotation = Quaternion.Euler(0,0,0);
}
if (whenlook == true ){
transform.localRotation = Quaternion.Euler(0,180,0);
}
}
}
void Start()
{
posbtnright = rightbtn.transform.position.y;
posbtnleft = leftbtn.transform.position.y;
posJumpBtn = jumpbtn.transform.position.y;
<b>rb = GetComponent();
anim = GetComponent();</b>
}
rb = GetComponent<RigidBody2D>();
anim = GetComponent<Animator>();