UnityNinja Community
Would you like to react to this message? Create an account in a few clicks or log in to continue.

UnityNinja CommunityLog in

UnityNinja - Video Game Development Community, including Resources, Forums, Marketplace & More.


descriptionC# - How to edit scripts on another Gameobject EmptyC# - How to edit scripts on another Gameobject

more_horiz
This Demo Code is for editing the value Health on ScriptTwo  by reducing the amount from ScriptOne Damage Value.

A similar effect can be done by using a raycast (as you see in common FPS Games) which will not set a target at all, but by checking against hitting a gameobject with a specific script and variable to reduce by.


e.g



Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
       if (Physics.Raycast(ray, 100))
           print("Hit something");        



Reference:

UNITY API (Sorry forum wont let me post the link but search in google unity api raycast)



--------------------------------------------------------------------------------------------------


                     RPG Targeting system Type Demo Code.


--------------------------------------------------------------------------------------------------

ScriptOne

Code:


using UnityEngine;
using System.Collections;

public class ScriptOne : MonoBehaviour {


    int Damage = 10;  
    GameObject Target;


   // Use this for initialization
   void Start () {

   }
   
   // Update is called once per frame
   void Update () {

        if (Input.GetKeyDown(KeyCode.Space))
        {
            try
            {
                Target.GetComponent<ScriptTwo>().Health -= Damage;
            }
            catch
            {
                if (Target == null)
                    print("You Do not have a Target!");
                else
                    print("Your Target Does not have ScriptTwo on it!");
            }
        }

   
   }
}





ScriptTwo


Code:


using UnityEngine;
using System.Collections;

public class ScriptTwo : MonoBehaviour {

    public int Health;

    void Start()
    {
        Health = 100;
    }

}

descriptionC# - How to edit scripts on another Gameobject EmptyRe: C# - How to edit scripts on another Gameobject

more_horiz
any chance you can go further into stats basic... with similar output and usage... 

Great Incite to this Btw 

Thanks

descriptionC# - How to edit scripts on another Gameobject EmptyRe: C# - How to edit scripts on another Gameobject

more_horiz
What more would you like to know? I can do all sorts from collision, triggers, raycast, targetting(rpg style)

descriptionC# - How to edit scripts on another Gameobject EmptyRe: C# - How to edit scripts on another Gameobject

more_horiz
Im scanning Current and ole FPS and RPGs for a base of what i would like to see and we can work from there...   I dont want a SYSTEM so to speak but i want to make sure i dont leave holes that potential would setback the scripting due to CHANGES in the whole structure..


eventually i want this to be a free video series that actually works and doesnt die after video 4..

descriptionC# - How to edit scripts on another Gameobject EmptyRe: C# - How to edit scripts on another Gameobject

more_horiz
Sure I attempted a video yesterday actually, a few times more to it. but I am not very good at explaining over a mic, I'll give it another shot and see how it goes, ill post up in the tutorial section if I get something I'm happy with.

descriptionC# - How to edit scripts on another Gameobject EmptyRe: C# - How to edit scripts on another Gameobject

more_horiz
Hey sorry for the long wait, I have been inactive for a while due to hospital... I'm not great with video tutorials. Ut ill be able to write up another doc like this with much more detail regarding UI in unity 5 and a combination of ways that xp can be granted in different forms etc rpg style fps kills and I might even dig into quests.

descriptionC# - How to edit scripts on another Gameobject EmptyRe: C# - How to edit scripts on another Gameobject

more_horiz
This is great, definitely will be helpful to many great contribution. I hope you are doing well recovering from the hospital

descriptionC# - How to edit scripts on another Gameobject EmptyRe: C# - How to edit scripts on another Gameobject

more_horiz
Thanks, I am mostly well now. I will be going through this again in greater detail so I miggt actually pull this one down but I feel it has good reference so I may just make a version 2 and seperate these both or may attempt another video for simplicity.

descriptionC# - How to edit scripts on another Gameobject EmptyRe: C# - How to edit scripts on another Gameobject

more_horiz
Hello i have been away recently for awhile as i am currently on UNI break, work has chewed up a lot of time, but i have been working on some small projects and hope to have some new tutorials out soon, unfortunately i am not that great at producing videos yet so i will stick to some old fashioned written tutorials with DEMO code provided, it has been far too long. if you would like to see some of my other content i am currently working on building a web server to host all my content as i had issues in the past with other hosts having my sites pulled down i will both try to upload my content here and to my personal forum @

krazorstudios.tk

Hope to see you all soon!

descriptionC# - How to edit scripts on another Gameobject EmptyRe: C# - How to edit scripts on another Gameobject

more_horiz
privacy_tip Permissions in this forum:
You cannot reply to topics in this forum
power_settings_newLogin to reply