News Forums RAIN General Discussion and Troubleshooting Getting value of a Script on RAIN?

This topic contains 1 reply, has 1 voice, and was last updated by  ZackHanzo 1 year, 3 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #32600

    ZackHanzo
    Participant

    Hi guys im new with unity and of course new with Rain. I follow all the tuts from the utube channel and all works good. Now im working with Meca, and all works good too.

    So.. my AI character, chases me, stop when he reachs my position and do the animation of the hit…. So… i get the point of all the tuts but:

    Now i want to control the death of my AI character, but i dont know how. I mean

    I have in the pistol a script which shoots, and if the AI character is in that layer/tag do all the things. I have a simple script to receive the damage with the function TakeDamage like this:

    `public class HealthEnemy : MonoBehaviour {

    public float hitPoints=100f;
    public float currentHitPoints;
    void Start () {

    currentHitPoints = hitPoints;

    }

    void Update () {

    }

    public void TakeDamage(float amt)
    {
    currentHitPoints -= amt;
    }

    }`

    Well… i have this script on the root of my AI character, to deal with the death. And now i want to use that variable currentHitPoints on Rain…. So if currentHitPoints>0 make all the stuff i put on the behaviour tree , and if currentHitPoints<=0 deal with the death of AI character and get destroyed after the animation…

    So, my question is, how i get that var (currentHitPoints) value on Rain? I tried making it public, and using a constraint with the condition currentHitPoints>0 but it didnt work.

    Anyone can help me? Or know any tut about this?

    PS: I think i could deal with the dead making a script who destroy the AI gameobject, and making it through scripting on the animador (like… animador.setBool(“Death”,true);) But i think its interesting to me understand how it works, to make new conditions like a animation when the AI received the hit… or so..

    • This topic was modified 1 year, 3 months ago by  ZackHanzo.
    #32639

    ZackHanzo
    Participant

    Well i was reading all the API/Wiki stuff, and i have no doubts that if you a good coder or experienced one you could understand how make that works, but to me, well i have tons of question…

    Following a example on the Wiki CustomMemory i did this:

    using System;
    using UnityEngine;
    using RAIN.Serialization;
    using RAIN.Memory;

    [RAINSerializableClass]
    public class BossEncounter : MemoryObject
    {
    private GameObject zombieGameObject;
    private float nowHealth;
    public BossEncounter (GameObject gameObject)
    {
    //Save the game object
    zombieGameObject = gameObject;

    //Get information on the game object
    GetTargetHealth();
    }

    public float GetTargetHealth()
    {
    //get the script component on the game object
    HealthEnemy health = zombieGameObject.GetComponent<HealthEnemy>() as HealthEnemy;

    if(health is HealthEnemy)
    {

    nowHealth= health.currentHitPoints;

    }

    return nowHealth;
    }
    }

    So…. i want to evaluate if nowHealth (aka health.currentHitPoints) is 0, for stop moving and destroy it if that GameObject takes that value or less). But it says “The asociate script is not loaded….” So i guess im not understanding what the API/Wiki is trying to tell me…

    And of course i dont know how to make it on the expresion stuff… I wanna do something like evaluate a expression in a constraint like:
    contraint
    nowHealth//health.currentHitPoints//>0
    -selector-> -constraint sensor 1 ==null patrol
    -constraint sensor 1 !=null detects->chases me
    ->constraint sensor 2!=null detects->hit me
    constraint
    nowHealth//health.currentHitPoints//<0
    -constraint move=false, animate //Dead animation//

    I already did all the following, and hitting stuff, and player receives damage when the zombie hits him, but i dont know how to manage this damage that the zombie received from Player on Unity.

    I have the proper script to receive damage (post bellow) , and im trying to make a var to acceed from unity like a condition of the current health, but i dont know how :(

    Maybe im not understand the wiki stuff, or the script shouldn be stored on the root of the GameObject or just i dont know… It has to be a easy thing, but i dont know how to reach to that goal.And i think it has to be there, due to the GetComponent stuff and not GetComponentInParent on the wiki/api

    • This reply was modified 1 year, 3 months ago by  ZackHanzo.
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.