Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Edos3306 · Oct 29, 2021 at 02:32 PM · basics

how to find the player without attaching a script to it

Hey. I want to start modding games but I quickly found out that I need to learn how to control everything without the editor, so I wanted to test some things and one of the things I wanted to do is to attach a movement script to the player via script but the script I wrote isnt working. here it is:

 public float speed;
 public GameObject Player;

 void Start()
 {
     Player = GameObject.FindWithTag("Player"); //trying to find the player via tags
 }

 void Update()
 {
     //movement
     Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0f, 0f);
     Player.transform.position = movement * Time.deltaTime * speed;
     //printing the player current position to the console
     Debug.Log(Player.transform.position.x);
     Debug.Log(Player.transform.position.z);
     Debug.Log(Player.transform.position.y);
 }

}

any ideas?

Comment
Add comment · Show 2
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 bdubbert · Oct 29, 2021 at 05:15 PM 0
Share

First - I think you probably meant

 Player.transform.position += ...

As far as finding the player - are you getting null reference exceptions to show that you did not find the player object? If it is getting to those Debug.Logs then you did find an object tagged as player.


Do you know that the Player object is Tagged as a player? If not, what do you know about the player object? If you know its name, you can use GameObject.Find(), if you know any script that is attached to it you can use GameObject.FindObjectOfType. Do you know if the player is publicly referenced by any other scripts, like a Game Manager script perhaps? If so you can grab the reference from that script. Other than that, if you don't know anything about the player object it will be pretty difficult to find it in the sea of objects in the scene.

avatar image logicandchaos · Oct 30, 2021 at 11:53 PM 0
Share

You are not finding player by script you are finding it by tag, you assign tags in the editor. If you put a script on it you can find it like that as well, you can also set the reference in the inspector.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by UnityPlum · Nov 01, 2021 at 01:04 AM

Did you add the Tag "Player" to the player object? If you did, try, GameObject.Find("Player") and name the Player object to "Player"

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 Edos3306 · Nov 02, 2021 at 01:49 PM 0
Share

hey yeah I added the Tag but the script isn't even working like it doesn't even debug the player position until I attach the script to an object in the editor but I was hoping I could get it to work without attaching the script to something cuz In modding you cant really do it.

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

131 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

Related Questions

Tutorials arent specific 1 Answer

Basic physics question 1 Answer

Array Declaration & Initialization- Inside and Outside Functions 2 Answers

Long Question 0 Answers

Adding Text to Canvas via script 4 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