Search Unity

Can someone help make my character look at the camera direction ?

Discussion in 'Scripting' started by gsantos1510, Sep 14, 2018.

  1. gsantos1510

    gsantos1510

    Joined:
    Sep 14, 2018
    Posts:
    3
    this is the code​
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Player : MonoBehaviour {
    6.  
    7.     public Animator Anim;
    8.     public Rigidbody Rbody;
    9.  
    10.     private float InputH;
    11.     private float InputV;
    12.  
    13.     // Use this for initialization
    14.     void Start () {
    15.    
    16.         Anim = GetComponent<Animator>();
    17.         Rbody = GetComponent<Rigidbody> ();
    18.  
    19.  
    20.     }
    21.     // Update is called once per frame
    22.     void Update () {
    23.  
    24.  
    25.  
    26.         if (Input.GetMouseButtonDown (0)) {
    27.             int n = Random.Range (0, 2);
    28.  
    29.            
    30.             if (n == 0) {  
    31.                 Anim.Play ("Punching", -1, 0f);
    32.             } else {
    33.                 Anim.Play ("Punching (1)", -1, 0f);
    34.             }
    35.         }
    36.        
    37.             InputH = Input.GetAxis ("Keyboard1");
    38.             InputV = Input.GetAxis ("Keyboard2");
    39.  
    40.             Anim.SetFloat ("InputH", InputH);
    41.             Anim.SetFloat ("InputV", InputV);
    42.    
    43.  
    44.             float moveX = InputH * 20f * Time.deltaTime;
    45.             float moveZ = InputV * 50f * Time.deltaTime;
    46.  
    47.             Rbody.velocity = new Vector3 (moveX, 0f, moveZ);
    48.  
    49.  
    50.  
    51.      
    52.         }
    53.     }
     
    Last edited: Sep 14, 2018
  2. BlackPete

    BlackPete

    Joined:
    Nov 16, 2016
    Posts:
    970
  3. winterfive

    winterfive

    Joined:
    May 21, 2018
    Posts:
    31
unityunity