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 /
This question was closed Feb 16, 2018 at 10:33 PM by nwmarkovic.
avatar image
0
Question by nwmarkovic · Feb 16, 2018 at 06:06 AM · prefabtransform.positioncloneinstantiate prefab

Instantiated clone GameObject spawning at wrong position.

I have script that is supposed to clone a canvas prefab whenever a enemy is hit, but when it clones it always clones to the same position, the canvas and text are both centered at (0,0,0). Here are the scripts, the first script controls the collision interaction and cloning, the second controls the floating of the text, I feel like the second one has a issue, but I cant find a solution.

Script 1: Prefab cloning

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class HurtEnemy : MonoBehaviour {
 
     public int damageToGive;
     public GameObject damageBurst;
     public Transform hitPoint; 
     public GameObject damageNumber;
     
     void OnTriggerEnter2D(Collider2D other)
     {
         if (other.gameObject.tag == "Enemy")
         {
             //Destroy(other.gameObject);
             other.gameObject.GetComponent<EnemyHealthManager>().HurtEnemy(damageToGive);
             Instantiate(damageBurst, hitPoint.position, hitPoint.rotation);
             GameObject clone = (GameObject)Instantiate(damageNumber, hitPoint.position, Quaternion.identity);
             clone.GetComponent<FloatingNumbers>().damageNumber = damageToGive;
             Debug.Log(hitPoint.position);
         }
     }
    
 }

Script 2

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class FloatingNumbers : MonoBehaviour {
 
     public float moveSpeed;
     public int damageNumber;
     public Text displayNumber;
 
 
     // Use this for initialization
     void Start () {
         
     }
     
     // Update is called once per frame
     void Update () {
         displayNumber.text = "" + damageNumber;
         transform.position = new Vector3(transform.position.x, transform.position.y + (moveSpeed * Time.deltaTime), transform.position.z);
         Debug.Log(transform.position);
 
     }
 }
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

2 Replies

  • Sort: 
avatar image
0

Answer by upasnavig90 · Feb 16, 2018 at 06:34 AM

Where you assigning hitPoint?? Instantiate(damageBurst, hitPoint.position, hitPoint.rotation); what is the value of hitPoint, if you are not assigning it, it will take default value.

Comment
Add comment · Show 1 · 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 nwmarkovic · Feb 16, 2018 at 06:42 AM 0
Share

the hitPoint is a point that is a child to the sword and its only purpose is to change the location on the sword the prefab clones. alt text and the value reads out from the Debug of the hitPoint as, (76.2, -33.9, 0.8) in the first script while in the second script the Debug of the transform.position reads out initially as, (0.0, 0.0, 0.8)

screenshot-9.png (5.0 kB)
avatar image
0

Answer by nwmarkovic · Feb 16, 2018 at 05:17 PM

When I Debug.Log(hitPoint.position) before and after the Instantiate the location is the same (76.2, -33.9, 0.8), so I don't know if the issue even lies in the code or in the prefab that is being cloned. alt text


screenshot-10.png (29.2 kB)
Comment
Add comment · 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

Follow this Question

Answers Answers and Comments

94 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

Related Questions

How do i apply some AISeeking code to all instances of a sprite, it is contained with the ship it is seeking but only 1 follows it 0 Answers

Placing Prefabs in Prefabs. 9 Answers

instantiated GameObject Prefab jumps in air after instantiate 1 Answer

Instantiated clones arent behaving the same as the prefab 1 Answer

Instantiate inactive,Making a GameObject active/instantiate 3 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