Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 Quackpants25 · Dec 08, 2019 at 11:21 AM · movementmovement scriptobject referencemovepositionmovements

How can I enable my capsule to move; object 'target' not recognized.

Hello there everyone. I'm new to unity and am trying to work through my first tutorial. Unfortunately, I'm having issues with the initial script being able to run. I was able to run this script on the first machine (Machine A), but unable to successfully run the script on the second (Machine B). The only difference when executing and attaching to unity is on Machine B I receive an error message "Field 'Mover.target' is never assigned to, and will always have its default value null." This does not appear on machine A. I'm not sure if the issues are related, but another discrepancy is System.Collection & System.Collections.Generic are also not utilized on Machine B.

The script I'm attempting is below. There is an object called 'target' within the scene. using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.AI;

public class Mover : MonoBehaviour { [SerializeField] Transform target;

 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         MoveToCursor();
     }
 }

 private void MoveToCursor()
 {
     Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
     RaycastHit hit;
     bool hasHit = Physics.Raycast(ray, out hit);
     if (hasHit)
     {
         GetComponent<NavMeshAgent>().destination = hit.point;
     }
 }

}

Note: I also attempted to run a more simple script to move the capsule to the target, and was unsuccessful on Machine B. This script is receiving the same error. Script below, using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.AI; public class Mover : MonoBehaviour { [SerializeField] Transform target;

 private void Update()
 {
     GetComponent<NavMeshAgent>().destination = target.position;
 }

}

Please help, I've tried several different methods of movement on this Machine, and have not been successful. This has really stopped me in my tracks for furthering any tutorial.,Hello everyone,

Comment
Add comment · Show 5
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 Fariborzzn · Dec 08, 2019 at 05:47 PM 0
Share

Hey Quackpants25 ! Your are getting error becuase you define a variable in your $$anonymous$$overScript Called Target! Target Is Filled In $$anonymous$$achine A but in $$anonymous$$achine B Its Not Assigned So Fill It with your target so it cant be null anymore! a good tip is always check your reference in this way if(target!=null) // make sure it is not null { //dothis }

avatar image Quackpants25 Fariborzzn · Dec 08, 2019 at 09:34 PM 0
Share

Thank you very much for your response @Fariborzzn! That absolutely makes sense, I'm just not sure how to execute & move forward. When you say fill it with your target, how would I do that? How do I get the target assigned in $$anonymous$$achine B? I thought I had been doing this by making the same objects and using the same scripts on $$anonymous$$achine A & B. Is this something that would be done to my object 'target' within the scene?

I'll play around with this information and attempt to google ways to implement in the meantime. Thanks again!

avatar image Fariborzzn Quackpants25 · Dec 08, 2019 at 10:01 PM 0
Share

Your Welcome Dear! [SerializeField] Transform target; // This is Filled You Had Define Click On the gameobject you can find it in $$anonymous$$over Component..

You Shoud Drag and Drop Your Target Object From Hierarchy To It

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

177 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

Related Questions

HOW TO MAKE A NPC GO FORWAR 0 Answers

How can i make it so that the object doesnt instantly go to top speed. Here is my code 1 Answer

How to make the sprite move a certain amount of pixels when a key is pressed? 1 Answer

MoveTowards is moveing my object to random position when i click it is already on a way 1 Answer

What should i write that when i press "Shift" it will speed up idk how shift is named? Here's the code: 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