Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Networking;
- public class SpellCaster : NetworkBehaviour
- {
- [SerializeField]
- GameObject spellPrefab;
- [SerializeField]
- Transform spellCastPoint;
- private Camera mainCamera;
- // Use this for initialization
- void Start ()
- {
- mainCamera = FindObjectOfType<Camera>();
- }
- void Reset()
- {
- spellCastPoint = transform.Find("SpellCastPoint");
- }
- // Update is called once per frame
- void Update ()
- {
- if (!isLocalPlayer)
- return;
- Ray cameraRay = mainCamera.ScreenPointToRay(Input.mousePosition);
- Plane groundPlane = new Plane(Vector3.up, Vector3.zero);
- float rayLength;
- if (groundPlane.Raycast(cameraRay, out rayLength))
- {
- Vector3 pointToLook = cameraRay.GetPoint(rayLength);
- Debug.DrawLine(cameraRay.origin, pointToLook, Color.red);
- transform.LookAt(new Vector3(pointToLook.x, transform.position.y, pointToLook.z));
- }
- if (Input.GetMouseButtonDown(0))
- {
- CmdSpawnSpell();
- }
- }
- [Command] // Functions for the server to deal with
- void CmdSpawnSpell()
- {
- GameObject instance = Instantiate(spellPrefab, spellCastPoint.position, spellCastPoint.rotation) as GameObject;
- NetworkServer.Spawn(instance);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement