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 Ethan91 · Aug 21, 2012 at 12:21 AM · getcomponentnewbiecs0246script reference

Getting static variable from another C# script using C#

I've read other post about this, I try to follow the same method but I keep getting an error. Here's the specific I have object name Projectile and Player

public class Projectile : MonoBehaviour {

public float ProjectileSpeed; public static float RELOADTIME = 0.05f; } In Player, I want to access RELOADTIME from Projectile. Here is what I did

public class Player : MonoBehaviour {
	
	public GameObject ProjectilePrefab;
	private float RELOADTIME;
	
	void Start () 
	{
		
		ProjectileScript projectileScript  = ProjectilePrefab.GetComponent();
		RELOADTIME = projectileScript.RELOADTIME;
	}
However, I keep getting this error Assets/Script/PlayerScript.cs(15,17): error CS0246: The type or namespace name `ProjectileScript' could not be found. Are you missing a using directive or an assembly reference?

I'm really frustrated :( I don't know what have I done wrong. Sorry, I'm a newbie in Unity. THANKS A LOT :(

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 aldonaletto · Aug 21, 2012 at 12:26 AM 0
Share

It seems that UA has eaten the type in GetComponent...

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by DaveA · Aug 21, 2012 at 12:22 AM

Your class is called Projectile. Did you name the file its in Projectile or ProjectileScript? It should be the same name as the file.

Comment
Add comment · Show 2 · 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 Ethan91 · Aug 21, 2012 at 01:31 AM 0
Share

$$anonymous$$y prefab named is Projectile. The script name is ProjectileScript. It still doesn't work when I change it to Projectile ins$$anonymous$$d

avatar image Ethan91 · Aug 21, 2012 at 01:33 AM 0
Share

WoW never$$anonymous$$d. I see what you are saying. THAN$$anonymous$$S A LOT

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Unity Quits Because Of Script!!! 1 Answer

Why can't I change another script's variable with this script? Thanks, 1 Answer

Error CS0246 1 Answer

How to use inputmanger while scripting? 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