I have created these two scripts but they can not work at the same time. In fact, when the first one works, the second one does not, although they are both active.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
public class Mevement : MonoBehaviour {
float dirX;
public float moveSpeed = 100f;
Rigidbody2D rb;
bool facingRight = true;
Vector3 localScale;
// Use this for initialization
void Start () {
localScale = transform.localScale;
rb = GetComponent<Rigidbody2D> ();
}
// Update is called once per frame
void Update () {
dirX = CrossPlatformInputManager.GetAxis ("Horizontal");
}
void FixedUpdate()
{
rb.velocity = new Vector2 (dirX * moveSpeed, 0);
}
void LateUpdate()
{
CheckWhereToFace ();
}
void CheckWhereToFace ()
{
if (dirX > 0)
facingRight = true;
else if (dirX < 0)
facingRight = false;
if (((facingRight) && (localScale.x < 0)) || ((!facingRight) && (localScale.x > 0)))
localScale.x *= -1;
transform.localScale = localScale;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
public class Jump : MonoBehaviour {
[Range (1,10)]
public float jumpVelocity;
bool jumpRequest;
bool ToccaTerra;
Transform tr;
void Start () {
tr = GetComponent<Transform> ();
}
void Update () {
if (CrossPlatformInputManager.GetButtonDown ("Jump")) {
jumpRequest = true;
}
}
void FixedUpdate () {
if (jumpRequest) {
if (tr.position.y <= -3.3) {
print ("ok1");
//GetComponent<Rigidbody2D> ().velocity = Vector2.up * jumpVelocity;
GetComponent<Rigidbody2D>().AddForce(Vector2.up * jumpVelocity, ForceMode2D.Impulse);
jumpRequest = false;
}
}
}
}
How can I solve this problem? Thank you in advance for the answers.