- Home /
Modifying a prefab
Hi, I want to make a multiplayer game where players can choose their stats and then they would spawn in the world, I made a simple leveling script (it doesn't modify anything yet, it simple changes useless values, but later, that values will change the player's stats)
using UnityEngine;
using System.Collections;
public class PlayerStats : MonoBehaviour {
public int agility;
public int health;
public int strenght;
public int pointsToSpend;
void Update () {
agility = Mathf.Clamp(agility, 0, 5);
health = Mathf.Clamp(health, 0, 5);
strenght = Mathf.Clamp(strenght,0,5);
pointsToSpend = 9 - agility - health - strenght;
if (Input.GetKeyDown(KeyCode.Y))
agility--;
if (Input.GetKeyDown(KeyCode.U) && pointsToSpend > 0)
agility++;
if (Input.GetKeyDown(KeyCode.H))
health--;
if (Input.GetKeyDown(KeyCode.J) && pointsToSpend > 0)
health++;
if (Input.GetKeyDown(KeyCode.N))
strenght--;
if (Input.GetKeyDown(KeyCode.M) && pointsToSpend > 0)
strenght++;
}
}
Then I would make a switch statement to choose the values to modify, but how do I modifiy a prefab's values?(This stats would be stored in playerPrefs) This script should be used in the menu, to change the prefab's values, and then when the player wants to he would jump in the world with his desired stats
$$anonymous$$y guess is that the concept of prefab is not meant to be editable at runtime. It's only meant to be instantiated. But you can store data in an external file that would be applied to the new instance of the prefab during runtime.