Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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 harpoaian · Nov 09, 2021 at 08:31 PM · gameobjectinstantiate2d-platformer2d-gameplay

Souls pickup mechanic (Like Dark Souls, BloodBourne)

Made some progress but I am still stuck! I think I have the logic down I just don't think I am executing it correctly. As of right now I have 2 prefabbed Nexa Stone(the souls mechanic), One is just one that drops from the enemy and a Nexa Stone for the player's stones to drop when they die. I have finally optimized my damage system and linked it with my health bar. I do this by just have a damage script with a public int that I can modify in the inspector and then I call it with a collider function (there is a point to this I promise, bare with me <3) SO after I got all of that done I thought I would be able to apply this solution to this problem but I'm not having any luck :/. Here is the relevant code

NexaStoneDeath Drop Script:

  using System.Collections;
     using System.Collections.Generic;
     using UnityEngine;
 
 public class NexaStoneDeathDrop : MonoBehaviour
 {
     public int deathStoneAmount;
 
     public GameObject Player;
 
     public GameObject deathStone;
 
     public GameObject myInstance;
 
     public PlayerStateMachine daPlayers;
 
     public void Start()
     {
         //deathStoneAmount = daPlayers.nexaStones.CurrentVal;
     }
 
     public void Update()
     {
         // deathStoneAmount = daPlayers.nexaStones.CurrentVal;
         myInstance = GameObject.Instantiate(deathStone, Player.transform.position, Quaternion.identity) as GameObject;
         myInstance.GetComponent<PlayerStateMachine>().nexaStones.CurrentVal = deathStoneAmount;
         DeathNexaStoneDrop(deathStoneAmount);
     }
     public int GetDeathStoneAmount()
     {
         return deathStoneAmount;
     }
 
     public void DeathNexaStoneDrop(int stoneamount)
     {
         if (daPlayers.isDead == true)
         {
             deathStoneAmount -= stoneamount;
             Instantiate(deathStone, transform.position, transform.rotation);
             Debug.Log("I should be running ");
         }
     }
 
     public void DeathNexaStonePickup(int stoneamount)
     {
         stoneamount += deathStoneAmount;
         Debug.Log("When I see this the stone count should go back to what it was before death");
     }
 
 }

When I call my DeathNexaStoneDrop in my Death() that is in my PlayerStateMachine Script it doesn't instantiate the object and the value of the players nexa stone doesnt transfer to the deathStoneAmount variable. The code below this is the relevant parts of my PlayerStateMachine

  Player thePlayer;
     
     public NexaStoneDeathDrop theDedStone;
 
     PlayerStateMachine players;
 
     void Start () 
     {
         rb = GetComponent<Rigidbody2D>();
         Beserker = GameObject.Find("BeserkerParent/Beserker");
         thePlayer = player.GetComponent<Player>();
         theDedStone = dedStone.GetComponent<NexaStoneDeathDrop>();
 
         isStunned = false;
 
         players = player.GetComponent<PlayerStateMachine>();
 
         chargingDamage = Beserker.GetComponent<BeserkerStatemachine>();
 
 
         health.CurrentVal = 100;
 
         spiritEnergy.CurrentVal = 100;
 
         nexaStones.CurrentVal = 0;
 
         Bullet.GetResetCharge();
         saberBullet.GetResetCharge();
 
         facingRight = true;
 
         hasWolfFormUnlocked = false;
 
         isRoyalWolfDead = false;
 
         inWolfForm = false;
 
         canAlphaCommand = true;
 
         wolfSense = false;
 
         isDead = false;
 
 
         fsm.Add (PlayerStates.IDLE, StateIdle);
         fsm.Add (PlayerStates.RUN, StateRun);
         fsm.Add (PlayerStates.ENTER_JUMP, StateEnterJump);
         fsm.Add (PlayerStates.IN_AIR, StateInAir);
         fsm.Add (PlayerStates.USE_WEAPON, WeaponFire);
         fsm.Add (PlayerStates.USE_BEAMSABER, BeamSaberAttack);
         fsm.Add(PlayerStates.TAKE_DAMAGE, DamageState);
         fsm.Add(PlayerStates.STUN, StunState);
         //fsm.Add(PlayerStates.DEATH, DeathState);
 
         fsm.Add(PlayerStates.WOLF, WolfState);
         fsm.Add(PlayerStates.WOLFENTER_JUMP, WolfStateEnterJump);
         fsm.Add(PlayerStates.WOLFIDLE, StateIdle);
         fsm.Add(PlayerStates.WOLFRUN, StateRun);
         fsm.Add(PlayerStates.WOLFIN_AIR, StateInAir);
         fsm.Add(PlayerStates.WOLFUSE_WEAPON, WeaponFire);
         fsm.Add(PlayerStates.WOLFUSE_BEAMSABER, BeamSaberAttack);
         fsm.Add(PlayerStates.WOLF_TAKE_DAMAGE, DamageState);
 
 
         SetState (PlayerStates.IDLE);
     }
 
 if(col.tag == "Pickup")
         {
             Debug.Log("I am pickedup");
 
            if(col.name == "NexaStone")
             {
                 Debug.Log("You Picked a NexaStone");
                 thePlayer.NexaStonePickupStuff(col.GetComponent<NexaStonePickup>().GetStoneAmount());
                 //nexaStones.CurrentVal++;
                 Destroy(col.gameObject);
             }
            if(col.name == "NexaStoneDeath")
             {
                 Debug.Log("NexaStone Recovered!");
 
                 theDedStone.DeathNexaStonePickup(col.GetComponent<NexaStoneDeathDrop>().GetDeathStoneAmount());
 
                 //thePlayer.NexaStonePickupStuff(col.GetComponent<NexaStonePickup>().GetStoneAmount());
                 // nexaStones.CurrentVal = nexaStones.CurrentVal;
                 Destroy(col.gameObject);
             }
            if(col.name =="Health")
             {
                 health.CurrentVal++;
                 Destroy(col.gameObject);
                 Debug.Log("You picked health");
             }
         }
  public void Respawn()
     {
         health.CurrentVal = 100;
 
         spiritEnergy.CurrentVal = 100;
 
         nexaStones.CurrentVal = 0;
 
         facingRight = true;
 
 
         inWolfForm = false;
 
         canAlphaCommand = true;
 
         wolfSense = false;
 
         isDead = false;
 
         player.transform.position = respawnLocation.transform.position;
 
         player.SetActive(true);
 
         SetState(PlayerStates.IDLE);
 
 
 
     }
  void Death()
     {
         isDead = true;
 
         if(isDead == true)
         {
             
 
            // int randIndex = UnityEngine.Random.Range(0, PickupTypes.Length);
 
             //Instantiate(PickupTypes[randIndex], transform.position, transform.rotation);
 
             player.SetActive(false);
 
 
             //theDedStone.DeathNexaStoneDrop(nexaStone);
 
             //nexaStones.CurrentVal = nexaStones.CurrentVal;
             // So in here make it so when the player dies a few things happen:
             //1. When they die they will go back to a previous shrine
             //2. The player will drop their Nexa Stones
             //3. Then make it so when the player dies they lose the stock of nexa stones or maybe a hollow knight mechanic with the wandering spirit?
             //4. Add a respawn timer so it feels natural ( do that after you get intial death state working)
             //5. Create a Respawn function that will work similar to the start function. This is important because everything needs to be reset when the player is killed.
             //6. Need to link the nexa stone functionality to death so when the player dies they drop the nexa stone and then they can go back and get the lost stones.
             //7. After this has all been implemented this will be working as desired.
 
             Respawn();
 
         }
     }
 
  public void DamageState()
     {
         thePlayer = player.GetComponent<Player>();
         players = player.GetComponent<PlayerStateMachine>();
         thePlayer.ColorTimeIncrease();
         if (thePlayer == null)
         {
             Debug.Log("PlayerStateMachine.Start() - We couldn't retrive the Player component");
         }
 
         if(players == null)
         {
             Debug.Log("PlayerStateMachine.Start() - We Couldn't retrive the PlayerStateMachine component");
         }
 
         if (hasBeenHit == false)
         {
             
            // health.CurrentVal--; //thePlayer.TakeDamage(GetComponent<Damage>().GetDamage());
             //players.playerHealth--;
             
 
             // if not working right add col. before get component
            // thePlayer.TakeDamage(GetComponent<Damage>().GetDamage());
 
             hasBeenHit = true;
 
             thePlayer.GetComponent<Renderer>().material.color = Color.red;
         }
         /*
         if (playerHealth <= 0)
         {
             Destroy(gameObject);
         }
         */
 
         if(health.CurrentVal <= 0)
         {
             isDead = true;
             if(isDead == true)
             {
                 Death();
             }
            // Destroy(gameObject);
         }
 
         else if(thePlayer.ColorTimer () >= thePlayer.ChangeGray())
         {
             thePlayer.GetComponent<Renderer>().material.color = Color.gray;
             thePlayer.ResetColorTimer();
             hasBeenHit = false;
             HandleHorizontalInput();
             SetState(PlayerStates.RUN);
         }
     }

So sorry for the long post but I am really struggling and could use all the help I could get. I am not the best coder so if I could get a explanation to the solution to this problem it will help me become a better Game Designer! Thank you for your time and help <3

Comment
Add comment
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

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.

Follow this Question

Answers Answers and Comments

219 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 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 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 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 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 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 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 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 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 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 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

Make a gameobject Trigger Trigger Colliders but not Other Colliders 1 Answer

Add 0.5f to Vector.Right on next instantiated object ? 1 Answer

Combine objects instantiated at runtime 2 Answers

Instantiate as child 3 Answers

Transform.position assign attempt not valid, and position is infinity on an object? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges