using UnityEngine;
public class NPC : MonoBehaviour
{
// Competency level range
public float minCompetency = 0.099f;
public float maxCompetency = 1.0f;
// Number of decimal places
public int decimalPlaces = 2;
// Actual competency level for this NPC instance
private float competencyLevel;
// Reference to the tool prefab
private GameObject assignedToolPrefab;
private float assignedToolDurability;
void Start()
{
// Generate random competency level for this NPC
competencyLevel = Random.Range(minCompetency, maxCompetency);
// Round competency level to the specified decimal places
competencyLevel = Mathf.Round(competencyLevel * Mathf.Pow(10, decimalPlaces)) / Mathf.Pow(10, decimalPlaces);
// Use competency level in NPC behavior or other logic
Debug.Log("NPC Competency Level: " + competencyLevel);
}
// Method to assign the tool to the NPC
public void AssignTool(GameObject toolPrefab, float durability)
{
assignedToolPrefab = toolPrefab;
assignedToolDurability = durability;
// You can now use 'assignedToolPrefab' and 'assignedToolDurability' in NPC logic
Debug.Log("Tool Assigned: " + assignedToolPrefab.name + ", Durability: " + assignedToolDurability);
}
}
using UnityEngine;
public class RandomizedTool : MonoBehaviour
{
public GameObject[] tools;
private GameObject assignedTool;
void Start()
{
// Randomly choose a tool from the list
assignedTool = tools[Random.Range(0, tools.Length)];
Debug.Log("Selected Tool: " + assignedTool.name);
// Attach the tool to the current GameObject (e.g., NPC)
GameObject toolInstance = Instantiate(assignedTool, transform.position, Quaternion.identity);
toolInstance.transform.parent = transform;
// You can use 'assignedTool' in tool behavior or other logic
Debug.Log("Tool Assigned: " + assignedTool.name);
}
// Method to access the assigned tool from other scripts
public GameObject GetAssignedTool()
{
return assignedTool;
}
}