dark light

1. Code to implement tag management

2. The code that realizes the click effect when you click on the ground



3. Realize the orientation of the character's mouse click


4. Control the animation playback of the task


5. Camera follow and field of view effect code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FollowPlayer : MonoBehaviour {


    private Transform player;
    private Vector3 offsetPosition;

    public float distance = 0;
    public float scrollSpeed = 10.0f;
    private bool isRotate = false;
    public float rotateSpeed = 10.0f;
	void Start () {
        player = GameObject.FindGameObjectWithTag("Player").transform;
        offsetPosition = transform.position - player.position;
        transform.LookAt(player.position); //Towards the protagonist
	}
	
	// Update is called once per frame
	void Update () {
        transform.position = offsetPosition + player.position;
        ScrollView();
        RotateView();
	}
    void ScrollView() //Handle the zoom-in and zoom-out effects of the field of view
    {
     // print(Input.GetAxis("Mouse ScrollWheel"));//Return to a negative value backward (zoom in) and slide forward to return a positive value (zoom out)
        distance = offsetPosition.magnitude; //magnitude calculates the offset distance
        distance += Input.GetAxis("Mouse ScrollWheel") * scrollSpeed;
        distance = Mathf.Clamp(distance, 2, 18); //Clamp limits the range of a variable
        offsetPosition = offsetPosition.normalized * distance; //normalized current vector
      
          
     
    }
      void RotateView()
    {
        //Input.GetAxis("Mouse X"); //Get the mouse sliding in the horizontal direction
        //Input.GetAxis("Mouse Y"); //Get the mouse sliding in the vertical direction
        if (Input.GetMouseButtonDown(1))
        {
            isRotate = true;
        }
        if (Input.GetMouseButtonUp(1))  
        {
            isRotate = false;

        }
        if (isRotate)
        {
            transform.RotateAround(player.position, player.up,rotateSpeed * Input.GetAxis("Mouse X"));
            Vector3 originalPos = transform.position;
            Quaternion originalRotation = transform.rotation;
          
            transform.RotateAround(player.position, transform.right,- rotateSpeed ​​* Input.GetAxis("Mouse Y")); //There are two properties affected, one position and one rotation
            float x = transform.eulerAngles.x;
            if (x < 10 || x > 80) // range limit
            {
                transform.position = originalPos;
                transform.rotation = originalRotation;
            }
        }
        offsetPosition = transform.position - player.position;  
    }
}

6. NPC production

mission system

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BarNPC : NPC {

    public TweenPosition questTween;
    public bool isInTask = false; //indicates whether it is in the task
    public int killCount = 0; //Indicates the progress of the task, several wild wolves have been killed
    public UILabel desLabel; //Task description
    //Refer to three buttons
    public GameObject acceptBtnGo;
    public GameObject okBtnGo;
    public GameObject cancelBtnGo;

    public GameObject quest;


    private PlayerStatus status; //Definition of character status script object
     void Start()
    {
       status = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerStatus>(); //Get a script and use the method of another script
    }


    void OnMouseOver() //When the mouse is over the collider, this method will be called every frame
    {

        if (Input.GetMouseButtonDown(0)) //When the old man is clicked, the method of displaying the panel will be called
        {
          if (isInTask)
            {
                ShowTaskProgress ();
            }
            else
            {
                ShowTaskDes ();
           }
            ShowQuest();
        }
    }
    void ShowQuest() //Display panel
    {
        questTween.gameObject.SetActive(true);
        questTween.PlayForward(); //Play forward
    }

    void HideQuest() //Hide the panel
    {
        questTween.PlayReverse(); //Play backwards
        questTween.gameObject.SetActive(false);
      //  quest.SetActive(false);

    }
    

    public void ShowTaskDes() //Method to display task description ok button
    {
        desLabel.text = "Task:\n Killed 10 wolves\n\nReward:\n1000 Gold";
        okBtnGo.SetActive(false);
        acceptBtnGo.SetActive(true);
        cancelBtnGo.SetActive(true);
    }

    public void ShowTaskProgress() //The method to display the task process accepts the button
    {
        desLabel.text = "Task:\n You have killed" + killCount + "\\n 10 wolves\n\nReward:\n1000 Gold";
        okBtnGo.SetActive(true);
        acceptBtnGo.SetActive(false);
        cancelBtnGo.SetActive(false);
    }
    public void OnCloseButton() // close button
    {
        HideQuest();
    }
    //The processing of the button click time on the task system task dialog box
    public void OnAcceptButtonClick()
    {
        ShowTaskProgress ();
        isInTask = true;//Indicates in the task
    }


    public void OnOkButton() //Ok button
    {
        if (killCount >= 10)
        { //mission accomplished
            status.GetCoint(1000); //Call the GetCoint method in the PlayerStatus script
            killCount = 0;
            ShowTaskDes ();


        }
        else
        {//The task is not completed
            HideQuest();
        }
        
    }
    public void OnCancelButton() //Cancel button
    {
        HideQuest();
    }
    

}

7. Click on different objects to display different icons

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CursorManager : MonoBehaviour {
    //Set the singleton mode, other scripts can call the method of this script
    public static CursorManager _instance;


    public Texture2D cursor_normal;
    public Texture2D cursor_npc_talk;
    public Texture2D cursor_attack;
    public Texture2D cursor_lockTagret;
    public Texture2D cursor_pick;

    private Vector2 hotspot = Vector2.zero; //Keep the original position
    private CursorMode mode = CursorMode.Auto; //Automatically select the mode
	void Start () {
        _instance = this; //equal to the current script
		
	}
    
    public void SetNormal() { //Set the normal icon
        Cursor.SetCursor(cursor_normal, hotspot, mode);

    }
    public void SetNpcTalk() //Set the icon of the dialog
    {
        Cursor.SetCursor(cursor_npc_talk,hotspot,mode);
    }
}


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325964975&siteId=291194637