Jump to content

C# custom script help


jax299

Recommended Posts

I created a script for a custom Auger Item which performs a script on the left mouse button click. I know the prefab has an Auger script attached when i build the asset, however, when i load the object in game I receive the following message in the debug window. "The referenced script (AugerRayTest) on this Behaviour is missing!" I'm not really sure where to go from here to correct this issue. Any help would be most appreciated.

Link to comment
Share on other sites

I created a script for a custom Auger Item which performs a script on the left mouse button click. I know the prefab has an Auger script attached when i build the asset, however, when i load the object in game I receive the following message in the debug window. "The referenced script (AugerRayTest) on this Behaviour is missing!" I'm not really sure where to go from here to correct this issue. Any help would be most appreciated.

 

Mono Behaviour scripts that are attached to your Unity objects get added to the Unity3d bundle as text objects only. That's why you are getting the error, since the script is detached from the prefab during exports.

 

You would probably have to add a SDX Script that handles it, and call it from the <property name="Class" value="MyAuger, Mods" />

Link to comment
Share on other sites

Thanks for the reply! I am using SDX 0.7.3 in my GodAuger mod folder i have another folder labeled Scripts. This is where I placed the ItemAugerRayTest.cs. Within the items.xml file = <property name="Class" value="ItemAugerRayTest, Mods"/> when i start up the game i receive the following ERR XML Loader: Loading and parsing 'items.xml' failed Exception: No item class 'ItemAugerRayTest,Mods found! I have been looking around all day trying to find an answer to this. I started going through the 7dtd sdx mod repository on github to view other mods with scripts and it would appear that mine match. Although i could not load them in game. I think this is due to the mods being built for A16? Do you know if SDX takes the .cs file and appends that to the Mods.dll? I am wondering if this is not being accomplished somehow? i also tried to write a class in the mod.dll using dnspy and no dice. Thanks again for any assistance.

Link to comment
Share on other sites

Thanks for the reply! I am using SDX 0.7.3 in my GodAuger mod folder i have another folder labeled Scripts. This is where I placed the ItemAugerRayTest.cs. Within the items.xml file = <property name="Class" value="ItemAugerRayTest, Mods"/> when i start up the game i receive the following ERR XML Loader: Loading and parsing 'items.xml' failed Exception: No item class 'ItemAugerRayTest,Mods found! I have been looking around all day trying to find an answer to this. I started going through the 7dtd sdx mod repository on github to view other mods with scripts and it would appear that mine match. Although i could not load them in game. I think this is due to the mods being built for A16? Do you know if SDX takes the .cs file and appends that to the Mods.dll? I am wondering if this is not being accomplished somehow? i also tried to write a class in the mod.dll using dnspy and no dice. Thanks again for any assistance.

 

I've never added a new Itemaction, so maybe SDX doesn't have hooks in there. If it does, then something like this may work:

 

The original Class is called "ItemActionRanged". We may have to do <property name="Class" value="AugerRayTest" />

 

Your class name would be called, with an inheritance on ItemActionAttack. ItemActionAugerRayTest : ItemActionAttack

 

You'd have to follow the rules of the ItemAction class for your script.

Link to comment
Share on other sites

Thanks for the help I appreciate it. I'm new to modding and writing scripts so there is certainly a lot I still have to learn. Anyways I tried your recommendation to inherit the ItemActionAttack. This is what I receive in SDX when i build the mod.

 

\SDXModding-master\Targets\7DaysToDie\Mods\GodAuger\Scripts\ItemActionAugerRayTest.cs(6,14): error CS0534: 'ItemActionAugerRayTest' does not implement inherited abstract member 'ItemAction.ExecuteAction(ItemActionData, bool)'

ERROR: Failed to compile Mods.dll

ERROR: Task Compile mod scripts failed

 

I'm not really sure how to fix this, sounds like i have to write some additional code into the script but i dont know how. If anyone could shed some light on this i would greatly appreciate it. I'll provide the code to my project below. I got the basics of it to work in unity but I needed to test some things in the game before building more onto it. I commented the destroy.object out so I could test the debug.log and pull some tags from the game.

 

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

 

 

public class ItemActionAugerRayTest : ItemActionAttack

{

private readonly Collider[] overlappers;

private Vector3 hit1vector;

 

void Start () {

}

void Update()

{

Ray ray = new Ray(transform.position, transform.forward);

Debug.DrawRay(ray.origin, ray.direction, Color.cyan);

if (Input.GetMouseButton(0))

{

RaycastHit Hit1;

if (Physics.Raycast(ray, out Hit1, 10.0f))

{

//Debug.Log(hit1.transform.name);

//Debug.Log(hit1.transform.position);

hit1vector = new Vector3(Hit1.transform.position.x, Hit1.transform.position.y, Hit1.transform.position.z + 5);

Collider[] colliders = GetOverLappers(hit1vector);

for each (Collider hit in colliders)

{

//Debug.Log(gameObject.transform.position);

Debug.Log(hit.GetComponent<Collider>().tag);

// if(hit.GetComponent<Collider>().tag == "Block")

// {

// Destroy(hit.gameObject);

//}

 

}

}

}

}

Collider[] GetOverLappers(Vector3 hit2)

{

return Physics.OverlapSphere(hit2, 5);

}

 

void FixedUpdate()

{

 

 

}

}

// Update is called once per frame

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...