• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by MadJohny · Jan 03, 2014 at 12:24 PM · instantiateprefabswitchmodifystats

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

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ABerlemont · Jan 03, 2014 at 12:50 PM 1
Share

My 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.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Instantied 2D Prefab Is Invisible 1 Answer

How can I position an instantiated row of prefabs? 1 Answer

How do I apply certain prefab changes with a Script? 1 Answer

How do I instantiate certain objects to appear in a specific spot? 3 Answers

when prefabs are spawned I want to touch them to destroy. help? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges