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 Afelium · Oct 29, 2018 at 02:07 PM · uitransformprefabcanvasclone

Prefab always instanciated at 0

Context: I'm making a 2D rpg and I've got an issue with damage numbers(numbers that should appear where the weapon hits an enemy and then float up and disappear after a few updates).

Damage number is a canvas prefab with a child text gameobject; To create the damageNumber I'm using this command:

 var clone=(GameObject)Instantiate(damageNumber,hitPoint.position,Quaternion.Euler(Vector3.zero));

 

where damageNumber is the canvas with the damage numbers,and hitPoint is an empty gameobject child of the weapon from which damage numbers should spawn,but instead they keep spawning at x:0 y:0 z:0 and then float up.

Here's the script that makes the numbers float up(attached to the canvas)

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class FloatingNumbers : MonoBehaviour {
 
     public float moveSpeed;//speed at which the number goes up
     public int damageNumber;//damage number shown
     public Text displayNumber;//refers to the text box child of the canvas
     // Use this for initialization
     void Start () {
         
     }
     
     // Update is called once per frame
     void Update () {
         displayNumber.text = "" + damageNumber;//shows damage number in the textbox
         transform.position=new Vector3(transform.position.x,transform.position.y+(moveSpeed*Time.deltaTime), transform.position.z);//makes the number go up.I think that the problem may be here;
     }
 }
 

Sorry for bad English I'm not a native speaker

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 zereda-games · Feb 19, 2019 at 08:37 AM 0
Share
 public GameObject prefab;
 public Transform spawnPosition;

 void Start(){
     var clone = (GameObject)Instatiate(prefab, spawnPosition.transform, Quatinion.identity);
 }

or

 public string PrefabName;
 public Transform spawnPosition;
 private GameObject prefab;
 void Start(){
     go=Resources.Load<GameObject >(PrefabName);
     var clone = (GameObject)Instatiate(prefab, spawnPosition.transform, Quatinion.identity);
 }

also:

your next part should be fine from what i can tell myself If floating up if your goal, But where it spawns is incorrect. Vector3.zero is = to 0x,0y,0z and i think "Euler" is world space corect me if i'm wrong That's your error isn't it 0,0,0, of world space. This isn't what you want, you want the local space of where the player is or object rather that is being damaged. and have it spawn aka appear above their head and then float up and out of the screen and then destroy.. Possibly making it fade along the way... is this not correct?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by v-ercart · Nov 15, 2018 at 10:46 PM

I bet the value of hitPoint.position is wrong. You can test this by commenting out the contents of your Update() function, and you'll probably see it sitting at 0,0,0 not moving. Part of the reason I think this is true is your transform.position line doesn't edit the x and z values, so the transform must be set to those values initially.

Try printing hitPoint.position to the debug log when you get hit.

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

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

257 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Does using multiple World Space Canvases affect performance? 0 Answers

Transform Position Are Different Each Other 1 Answer

UI Canvas Anchor points are stuck in the bottom left corner and disabled when in overlay mode. 1 Answer

Assign main camera to a prefab with a canvas 0 Answers

Saving canvas to prefab 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