Advertisement
Guest User

Player

a guest
Feb 21st, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Player : MonoBehaviour {
  5. public float speed;
  6. private bool walk;
  7. private Rigidbody2D playerRb;
  8.  
  9. public GameObject prefab;
  10. public Transform arma;
  11. public float forcaTiro;
  12. // Use this for initialization
  13. void Start () {
  14. playerRb = GetComponent<Rigidbody2D> ();
  15.  
  16. }
  17.  
  18. // Update is called once per frame
  19. void Update () {
  20. float horizontal = Input.GetAxisRaw ("Horizontal");
  21.  
  22. if(horizontal != 0){
  23. walk = true;
  24. }else{
  25. walk = false;
  26. }
  27.  
  28. if(Input.GetKeyDown (KeyCode.C)){
  29. GetComponent<Animator> ().SetTrigger ("attack");
  30. Atirar ();
  31. }else{
  32. //GetComponent<Animator> ().Set ("atacar");
  33. }
  34.  
  35. playerRb.velocity = new Vector2 (horizontal * speed,playerRb.velocity.y);
  36.  
  37.  
  38. }
  39.  
  40. void Atirar(){
  41. GameObject tempPrefab = Instantiate (prefab,arma.position,Quaternion.identity) as GameObject;
  42. tempPrefab.GetComponent<Rigidbody2D> ().AddForce (new Vector2(forcaTiro,0));
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement