Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

enemy ai not losing health

Discussion in 'Getting Started' started by badassgamer, Jun 8, 2015.

  1. badassgamer

    badassgamer

    Joined:
    Apr 26, 2015
    Posts:
    140
    1. i imported a 3d model from makehuman to unity3d with help of blender and i apllied enemy's health script to that model because i want him as a enemy ai and the model does not have any collider attached so i tried different collider but he still does not lose health . here are the enemys'health script
    2. #pragma strict
      var Health = 100;
      function Update ()
      {
      if(Health <= 0)
      {
      Dead();
      }
      }
      function ApplyDammage (TheDammage : int)
      {
      Health = Health - TheDammage;
      }
      function Dead()
      {
      Destroy (gameObject);
      }

    3. and here are the melee script
    4. #pragma strict
      var TheDammage : int = 50;
      var Distance : float;
      var MaxDistance : float = 1.5f;
      var TheMace : Transform;

      function Update (){

      if(Input.GetButtonDown("fire1")){
      //attackAnimation

      TheMace.GetComponent(Animation).Play("attack");
      //attack function
      AttackDammage();
      }
      }
      function AttackDammage ()
      {
      //Attack function
      var hit : RaycastHit;
      if (Physics.Raycast (TheMace.transform.position,TheMace.transform.TransformDirection(Vector3.forward), hit))
      {
      if(hit.distance < MaxDistance)
      {
      hit.transform.SendMessage("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver);
      }
      }
      if (Input.GetKey (KeyCode.LeftShift))
      {
      TheMace.GetComponent(Animation).CrossFade("Sprint");
      }
      }
     
  2. blizzy

    blizzy

    Joined:
    Apr 27, 2014
    Posts:
    775
    Please use CODE tags when posting source code. It makes it easier on everyone's eyes.
     
  3. badassgamer

    badassgamer

    Joined:
    Apr 26, 2015
    Posts:
    140
    sorry iam new to this thread so dont know how to post