Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Player : MonoBehaviour {
- public float speed;
- private bool walk;
- private Rigidbody2D playerRb;
- public GameObject prefab;
- public Transform arma;
- public float forcaTiro;
- // Use this for initialization
- void Start () {
- playerRb = GetComponent<Rigidbody2D> ();
- }
- // Update is called once per frame
- void Update () {
- float horizontal = Input.GetAxisRaw ("Horizontal");
- if(horizontal != 0){
- walk = true;
- }else{
- walk = false;
- }
- if(Input.GetKeyDown (KeyCode.C)){
- GetComponent<Animator> ().SetTrigger ("attack");
- Atirar ();
- }else{
- //GetComponent<Animator> ().Set ("atacar");
- }
- playerRb.velocity = new Vector2 (horizontal * speed,playerRb.velocity.y);
- }
- void Atirar(){
- GameObject tempPrefab = Instantiate (prefab,arma.position,Quaternion.identity) as GameObject;
- tempPrefab.GetComponent<Rigidbody2D> ().AddForce (new Vector2(forcaTiro,0));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement