Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by lbryan212 · Feb 07, 2019 at 02:09 AM · instantiatemovingdecaltop down shooterblood

2D Top Down | Instantiate on player position and stop moving instantly

So far the blood splatters appear from an array perfectly. The problem is when i instantiate the blood splatters they follow the player, when i just need them to spawn on the positions he was hit with a bullet until it fades away/deletes etc.

I'm pretty decent at piecing c# together now so if anyone can share some knowledge on my situation I'd appreciate it.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by lbryan212 · Feb 07, 2019 at 08:35 PM

@xxmariofer any thoughts?

Comment
Add comment · Show 5 · Share
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 xxmariofer · Feb 07, 2019 at 09:17 PM 0
Share

hello, i cant really tell you much without checking your code, share the code of blood splatters and the code in which you instantiate it please.

avatar image lbryan212 xxmariofer · Feb 08, 2019 at 04:02 PM 0
Share

@xxmariofer I keep a ref to my bloodSplat prefab on my health script. When a bullet hits a player, the bullet calls the spawnblood method from the health script. I'm just trying to figure out the best way to spawn the bloodprefab only on the vectors where the player was hit.

Here's the bullet:


  private void OnTriggerEnter2D(Collider2D other)
     {
         Health health = other.gameObject.GetComponent<Health>();
         Name name = other.gameObject.GetComponent<Name>();
         if (health.isAlive)
         {
             if (bulletDmg < health.cur_health)
             {
                 other.gameObject.GetComponent<Health>().TakeDamage(bulletDmg);
                 // Debug.Log("Bullet detected");
                 Destroy(gameObject);
                 
                 health.lastPosition = transform.position;
                 health.blood = true;
                 health.SpawnBlood();

Here's the health script:


 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class Health : $$anonymous$$onoBehaviour {
     public Game$$anonymous$$anager game$$anonymous$$anager;
 
     public Vector3 bloodSpot = Vector3.zero;
     
 
     public string playerName;
     public string killedBy;
     
     public float max_health = 100f;
     public float cur_health = 0f;
     public bool isAlive;
     public bool blood;
 
     public bloodHolder bHolder;
 
 
     public Transform bloodLocation;
 
     public void Location()
     {
         
 
 
     }
 
 
     public void SpawnBlood()
     {
         
         bHolder.SetSprite();
         bloodHolder blood = (bloodHolder)Instantiate(bHolder, bloodLocation);
         
 
     }
 
     // Use this for initialization
     void Start () {
 
         cur_health = max_health;
         
 
         isAlive = true;
     }
 
 
 
     public void TakeDamage(float amount)
     {
         if (cur_health <= 0)
             return;
 
         cur_health -= amount;
         
 
 
     }
 
 
 
   
 
 
 
     // Update is called once per frame
     void Update () {
 
 
    //     healthBar.value = cur_health;
 
 
 
         if(cur_health <= 0)
         {
             isAlive = false;
             cur_health = 0;
             game$$anonymous$$anager.last$$anonymous$$illed = playerName;
             
             
         }
         else
         {
             isAlive = true;
         }
 
         
 
 
 
 
     }
 
     
 
 }
 


avatar image xxmariofer lbryan212 · Feb 08, 2019 at 04:27 PM 0
Share

hello, where is the var lastPosition of the Health class? and whats the transform bloodlocation? you want the object to spawn at bloodlocation but dont have his movement you should change that line to this,

  public void SpawnBlood()
  {        
      bHolder.SetSprite();
      bloodHolder blood = (bloodHolder)Instantiate(bHolder);
      blood.transform.position = bloodLocation.position;
  }
Show more comments

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

188 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

Related Questions

Moving a spawned shuriken 2 Answers

Projectile Instantiating at opposite position 0 Answers

Endless Runner map instantiate 0 Answers

Display Array GameObject store in Simple JSON 1 Answer

instantiate 1 only each time not clone all of whats on screen continuoslly 0 Answers


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