Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 rOBY GAMES · Mar 29, 2015 at 11:20 AM · c#errorplayertextpoint

Error C # script FloatingText in Unity.

Salve a tutti!

Sto lavorando ad un progetto 2d platform. Ho due script in C# col nome FloatingText e PointStar. Sulla console mi da 2 errori.

1° errore al numero 12, sullo script FloatingText con scritto questo:

NullReferenceException: Object reference not set to an instance of an object FloatingText.Show (System.String text, System.String style, IFloatingTextPositioner positioner) (at Assets/x ninja/CSharp Script/FloatingText.cs:12) PointStar.OnTriggerEnter2D (UnityEngine.Collider2D other) (at Assets/x ninja/CSharp Script/PointStar.cs:29)

 using UnityEngine;
 using System.Collections;
 
 public class FloatingText : MonoBehaviour 
 {
     private static readonly GUISkin Skin = Resources.Load<GUISkin>("GameSkin");
 
     public static FloatingText Show(string text, string style, IFloatingTextPositioner positioner)
     {
         var go = new GameObject("Floating Text");
         var floatingText = go.AddComponent<FloatingText>();
         floatingText.Style = Skin.GetStyle(style);
         floatingText._positioner = positioner;
         floatingText._content = new GUIContent(text);
         return floatingText;
     }
 
     private GUIContent _content;
     private IFloatingTextPositioner _positioner;
 
     public string Text { get { return _content.text; } set { _content.text = value; }}
     public GUIStyle Style { get; set; }
 
     public void OnGUI ()
     {
         var position = new Vector2();
         var contentSize = Style.CalcSize(_content);
         if (!_positioner.GetPosition(ref position, _content, contentSize))
         {
             Destroy(gameObject);
             return;
         }
 
         GUI.Label(new Rect(position.x, position.y, contentSize.x, contentSize.y), _content, Style);
     
     }
 }
 

I put the script where IFloatingTextPositioner assigns an error.

 using UnityEngine;
 using System.Collections;
 
 public interface IFloatingTextPositioner 
 {
 
     bool GetPosition(ref Vector2 position, GUIContent content, Vector2 size);
 }
 

I post also the script PointStar at number 29 gives an error.

 using UnityEngine;
 using System.Collections;
 
 public class PointStar : MonoBehaviour,  IPlayerRespawnListener
 {
 
     public GameObject Effect;
     public int PointsToAdd = 10;
     public AudioClip HitStarSound;
     public Animator Animator;
     public SpriteRenderer Renderer;
 
     private bool _isCollected;
 
     public void OnTriggerEnter2D(Collider2D other)
     {
 
         if (_isCollected)
             return;
 
         if (other.GetComponent<Player>() == null)
             return;
 
         if (HitStarSound != null)
             AudioSource.PlayClipAtPoint(HitStarSound, transform.position);
 
         GameManager.Instance.AddPoints(PointsToAdd);
         Instantiate(Effect, transform.position, transform.rotation);
         FloatingText.Show(string.Format("+{0}!", PointsToAdd), "PointStarText", new FromWorldPointTextPositioner(Camera.main, transform.position, 1.5f, 50));
     
         _isCollected = true;
         Animator.SetTrigger("Collect");
     }
 
     public void FinishAnimationEvent()
     {
         Renderer.enabled = false;
         Animator.SetTrigger("Reset");
     }
 
     public void OnPlayerRespawnInThisCheckpoint(Checkpoint checkpoint, Player player)
     {
         _isCollected = false;
         Renderer.enabled = true;
     }
     }
 

2nd error at number 27, again on the script FloatingText, saying this:

NullReferenceException: Object reference not set to an instance of an object FloatingText.OnGUI () (at Assets / x ninja / CSharp Script / FloatingText.cs: 27)

Thank You.

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 JigneshKoradiya · Mar 29, 2015 at 07:17 PM

public static FloatingText_Show(string text, string style, IFloatingTextPositioner positioner)

replace this line first

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

21 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

Related Questions

Trying to find what player inputed in Text Input field 1 Answer

Error CS1061 I can't find a solution! [C#] 1 Answer

Distribute terrain in zones 3 Answers

How do I solve this error? 2 Answers

enemy detect player then attack - c# 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