• 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 Sal1mus · Jun 11, 2018 at 10:12 PM · 3d

Touch Move character

Hi everyone! I'm noob in Unity. Can somebody help me pls? So. I have 2 or more characters on the board 9x12 cells. If I touch character, cells near him (left,right,back,back left,back right, front, front left, front right) must change color and activated. Then if I touch some of the activated cell, character must run with running animation to touched cell. If I touch not activated cell, character must stay on his position. If character 2 stay on cell near character 1 and I touch character 1, cells near character 1 must activated and change color, except cell on witch stay character 2. My English is poor, and this must be show what I want. https://youtu.be/FRwIreenNx8

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
Best Answer

Answer by PedroAK · Jun 12, 2018 at 01:32 AM

You can set a Raycast leaving from the cursor position to the "Square" and check if it is in players range and then if it is you can setup a NavMesh to move the player there when you click it

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 Sal1mus · Jun 12, 2018 at 04:52 PM 0
Share

Thanks Pedro. But it's hard for me now. Can you give an any example pls, it's will be easer to understand. Thanks a lot

avatar image PedroAK Sal1mus · Jun 12, 2018 at 05:47 PM 0
Share

No problem

For that you will need to shoot a Raycast from the Camera to the $$anonymous$$ouse Position you can do that with:

 Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
 RaycastHit hit;
     if (Physics.Raycast (ray, out hit, 2F)) {
                   //Then do some code to the hit
         }

after that you check the hitted object

     Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
     RaycastHit hit;
         if (Physics.Raycast (ray, out hit, 2F)) {
                       if(hit.collider.gameObject....) //Here you just check if this square is ok for the player to go dont know how you are doing this system so i cant help you there sorry
             }

After Checking we go to the player moving

You will need to add the Nav$$anonymous$$eshAgent componentToIt

then you have in the script at the top to import

 import UnityEngine.AI;

then you make the player move to the square it clicked

         Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
         RaycastHit hit;
             if (Physics.Raycast (ray, out hit, 2F)) {
                           if(hit.collider.gameObject....){
                                      GetComponent<nav$$anonymous$$eshAgent>().SetDestination(//Here the position of the square);
                           }
                 }

For making it easier you can also set the variable on void Start()

 public Nav$$anonymous$$eshAgent nav$$anonymous$$eshAgent;
 
 void Start(){
        nav$$anonymous$$eshAgent = GetComponent<Nav$$anonymous$$eshAgent>();
 }

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

98 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

Related Questions

Interactive Textures? 1 Answer

How to achieve squash and stretch on characters similar to 3D Mario games 0 Answers

Button Help 1 Answer

ScreenToWorldPoint & Screen.width 1 Answer

Is there a constant for the FOV? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges