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 » Tutorials » C# - How to edit scripts on another Gameobject

C# - How to edit scripts on another Gameobject

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

aquilinajake


Member [Lv. 3]
Member [Lv. 3]
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;
    }

}

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

supamigit


Member [Lv. 3]
Member [Lv. 3]
any chance you can go further into stats basic... with similar output and usage... 

Great Incite to this Btw 

Thanks

View user profile

aquilinajake


Member [Lv. 3]
Member [Lv. 3]
What more would you like to know? I can do all sorts from collision, triggers, raycast, targetting(rpg style)

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

supamigit


Member [Lv. 3]
Member [Lv. 3]
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..

View user profile

aquilinajake


Member [Lv. 3]
Member [Lv. 3]
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.

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

aquilinajake


Member [Lv. 3]
Member [Lv. 3]
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.

View user profile http://jakeaquilina.weebly.com/
This is great, definitely will be helpful to many great contribution. I hope you are doing well recovering from the hospital

View user profile http://www.youtube.com/user/misterninjaboy

aquilinajake


Member [Lv. 3]
Member [Lv. 3]
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.

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

aquilinajake


Member [Lv. 3]
Member [Lv. 3]
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!

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