I will try to explain clearly what I try to do with a simple example.
This is an example and not exactly what I want to do I explain later
I have a cube and a sphere in it and I want to show/hide the sphere using an event.
Here is the simple object.
I have done a script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CustomScriptTest : MonoBehaviour {
public void TestFunction(bool active)
{
gameObject.SetActive (active);
}
}
Alles anzeigen
The script is on the child object (for people think I missed this part). I already tried to put the script on the parent object without success.
Has you can see on the above screen the event is properly set.
Here the server object script.
[Serialized]
public partial class CustomTestItem : WorldObjectItem<CustomTestObject>
{
public override string FriendlyName { get { return ""; } }
public override string Description { get { return ""; } }
static CustomTestItem()
{ }
}
[Serialized]
public partial class CustomTestObject : WorldObject
{
public override string FriendlyName { get { return ""; } }
[Serialized] private bool isActive;
public override InteractResult OnActRight(InteractionContext context)
{
isActive = !isActive;
SetAnimatedState("ShowChild", isActive);
return base.OnActRight(context);
}
protected override void Initialize()
{ }
}
Alles anzeigen
I just want that when I right click on the cube the sphere show and hide.
I want to say that I don't need to have a custom script for doing that.
I can just do this.
This work fine with the above script.
If you want to tell me why you don't use the above solution if it's work.
It's because I can't do everything with that.
Imagine (don't ask me why) I want to change the color of the material dynamically with constant for the red, blue and green color.
Here is the new code.
public class CustomScriptTest : MonoBehaviour {
public void TestFunction(float value)
{
gameObject.GetComponent<MeshRenderer> ().material.color = new Color (value, value * 0.5f, value * 0.25f);
}
}
I change the boolean event to float event.
I change the OnActRight function.
[Serialized] private float newColor;
public override InteractResult OnActRight(InteractionContext context)
{
newColor += 0.1f;
if (newColor >= 1f) // Cause the color in unity is between 0 and 1
newColor = 0f;
SetAnimatedState("ChangeColor", newColor);
return base.OnActRight(context);
}
Alles anzeigen
I know this is stupid to try to do that, but it's just to show that without a custom script I can't do it.
Thanks everyone for reading my problems and trying to help.