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
Share
Go down
Member [Lv. 0]
Member [Lv. 0]
Posts : 1
Points : 1111
Rep : 0
Join date : 2015-08-04
View user profile

fps tutorial

on Sat Aug 08, 2015 10:54 am
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
Member [Lv. 3]
Member [Lv. 3]
Posts : 25
Points : 1780
Rep : 7
Join date : 2013-12-14
View user profile

Re: fps tutorial

on Tue Sep 08, 2015 2:00 am
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...
avatar
Member [Lv. 3]
Member [Lv. 3]
Posts : 45
Points : 1424
Rep : 3
Join date : 2015-08-30
Age : 23
Location : Melbourne
View user profilehttp://jakeaquilina.weebly.com/

Re: fps tutorial

on Mon Sep 14, 2015 6:34 am
Message reputation : 100% (1 vote)
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.
Back to top
Permissions in this forum:
You cannot reply to topics in this forum