Search Unity

could help me? jump(clone) and turn character

Discussion in 'Scripting' started by chuckthedog90, Aug 4, 2020.

  1. chuckthedog90

    chuckthedog90

    Joined:
    Aug 4, 2020
    Posts:
    1
    I have this problem I can not turn to the character and jump clones generated prefab


    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class PlayerController : MonoBehaviour
    7. {
    8.     public float MaxSpeed = 12f;
    9.     public float speed = 8f;
    10.     public bool suelo;
    11.     public float FuerzaDeSalto = 10.5f;
    12.     public GameObject sonidojump;
    13.     private Rigidbody2D body;
    14.     private Animator anime;
    15.     private bool saltar;
    16.     // Start is called before the first frame update
    17.     void Start()
    18.     {
    19.         body = GetComponent<Rigidbody2D>();
    20.         anime = GetComponent<Animator>();
    21.     }
    22.  
    23.     // Update is called once per frame
    24.     void Update(){
    25.  
    26.         anime.SetFloat("Speed", Mathf.Abs(body.velocity.x));
    27.         anime.SetBool("suelo", suelo);
    28.         float direccion = Input.GetAxis("Horizontal");
    29.         body.velocity = new Vector3(direccion * speed, body.velocity.y, transform.position.z);
    30.         Debug.Log(body.velocity.x);
    31.  
    32.         if (Input.GetKeyDown(KeyCode.Z) && suelo){
    33.             saltar = true;
    34.             Instantiate(sonidojump);
    35.         }
    36.         if (saltar){
    37.             body.AddForce(Vector2.up * FuerzaDeSalto, ForceMode2D.Impulse);
    38.             saltar = false;
    39.         }
    40.     }
    41. }