Forum rules - please read before posting.

Draw on scene using touch screen

Hello!

I'm making a puzzle where the user must connect dots between star patterns. In the second phase of the puzzle, I'd like the user to be able to draw lines with their fingers to connect the two dots. In the first phase the user just clicks the dots, and the line is drawn using line renderer. I can't figure out how to expand on this for the second phase, where the users could create visible "drawings" of their lines while connecting dots with them. So any help regarding this would be greatly appreciated. The idea is that if the user does not connect, say, two hotspots with the line, the line disappears when the user lifts their finger. How can I achieve this?

Comments

  • I'm not totally clear on the difference between phase one and two. Does phase two involve drawing a line across many dots, with a single click/finger held down?

    You'll need to rely on custom scripting - though you could potentially rely on AC's Hotspots and event system to detect where the cursor is.

    Are you using custom scripting for the first phase? If you can share your current code, it may be possible to adapt for the second.

  • Hey Chris!

    In the first phase, the users will connect the stars with lines just by tapping the hotpsots, and the line is drawn automatically, using line renderer. The line is drawn only from one point to another - there are a few hotspots the user can choose, and the constellation is drawn as a single "path" depending on the hotspots the player clicks. The only custom script I'm using in the first phase is a simple script that draws the line between two points, and it is activated with Object - Call Event action.

  • You can make use of AC's OnHotspotInteract and OnHotspotSelect custom events - so that clicking a Hotspot begins the drawing mechanic, and selecting other Hotspots draws points.

    Here's an example script, that should give you the basis for further tweaking. Attach to each Hotspot that a line can begin from, and assign a unique LineRenderer component in its Inspector:

    using System.Collections.Generic;
    using UnityEngine;
    using AC;
    
    public class LineDrawingExample : MonoBehaviour
    {
    
        public LineRenderer lineRenderer;
        List<Hotspot> hotspots = new List<Hotspot> ();
        private static LineRenderer activeLine;
    
        void OnEnable ()
        {
            EventManager.OnHotspotInteract += OnHotspotInteract;
            EventManager.OnHotspotSelect += OnHotspotSelect;
            UpdateLine ();
        }
    
        void OnDisable ()
        {
            EventManager.OnHotspotInteract -= OnHotspotInteract;
            EventManager.OnHotspotSelect -= OnHotspotSelect;
        }
    
        void Update ()
        {
            if (KickStarter.playerInput.GetMouseState () == MouseState.RightClick) activeLine = null;
        }
    
        void OnHotspotInteract (Hotspot hotspot, AC.Button button)
        {
            if (hotspots.Count == 0 && hotspot.gameObject == gameObject)
            {
                activeLine = lineRenderer;
                hotspots.Add (hotspot);
                UpdateLine ();
            }
        }
    
        void OnHotspotSelect (Hotspot hotspot)
        {
            if (hotspots.Count == 0 || hotspots.Contains (hotspot) || activeLine != lineRenderer) return;
    
            hotspots.Add (hotspot);
            UpdateLine ();
        }
    
        void UpdateLine ()
        {
            lineRenderer.positionCount = hotspots.Count;
            for (int i = 0; i < hotspots.Count; i++)
            {
                lineRenderer.SetPosition (i, hotspots[i].GetIconPosition ());
            }
        }
    
    }
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.