Unity Ninja Unity 3D Forum
To have exclusive access to all downloads, recourses and links within this forum, a free registered account is required. Just a heads up Wink

You are not connected. Please login or register

Unity Ninja Unity 3D Forum » General Dicussions » fps tutorial

fps tutorial

View previous topic View next topic Go down  Message [Page 1 of 1]

1 fps tutorial on Sat Aug 08, 2015 10:54 am

thebrownmamba


Member [Lv. 0]
Member [Lv. 0]
In MisterNinjas fps tutorial he shows how to get the player to damage and all but I can't figure out how to make the enemy do damage to the player

View user profile

2 Re: fps tutorial on Tue Sep 08, 2015 2:00 am

supamigit


Member [Lv. 3]
Member [Lv. 3]
You need to recreate the EnemyHealth and make it for the Player and then apply similar damage from scripts the player uses.. i added a p to see differences in code..
IE
Code:
#pragma strict

var Health = 100;

function ApplyDammage (TheDammage : int)
{
   Health -= TheDammage;
   
   if(Health <= 0)
   {
      Dead();
   }
}

function Dead()
{
   Destroy (gameObject);
}
becomes
Code:
NAMED PlayerHealth

var pHealth = 100;

function pApplyDamage (pTheDammage : int)
{
   pHealth -= pTheDammage;
   
   if(pHealth <= 0)
   {
      pDead();
   }
}

function pDead()
{
   Destroy (gameObject);
}
Give the enemy a Damage like you did for the player bullet shooting..
Code:
var pDamage = 100;

function OnCollisionEnter (info : Collision)
{
   info.transform.SendMessage("pApplyDamage", pDamage, SendMessageOptions.DontRequireReceiver);
}

hope this pushes you to right direction.. I would could should write it to teach you but im not a fan of JS as for uni standards and C# is been the push by ALL the company's iv spoken to offering JOBS...

View user profile

3 Re: fps tutorial on Mon Sep 14, 2015 6:34 am

aquilinajake


Member [Lv. 3]
Member [Lv. 3]
you could also give your Enemy a Gun if its an FPS, and have them raycast to you. and get the hit infomation.


e.g (C# Example)

Code:

public int Damage = 10;
RaycastHit hit;

 Ray ray;
           

            if (Physics.Raycast(transform.position, Vector3.forward, out hit, 250f))
            {
                Debug.DrawLine(transform.position, hit.point, Color.red, 2f);

            if(hit.collider.tag == "Player")
                hit.collider.GetComponenet<HealthScript>().Health -= Damage;
            }


Just make sure that the HealthScript is the script that has the Health you want to minus on your player.

View user profile http://jakeaquilina.weebly.com/

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum