Hello, I am trying to make a game where you can click on a character to select that character as your playable character using a hotspot switch call. So far, I am able to switch player characters, however, I am having a bit of trouble on the nuances.
My script is throwing a monobehavior issue and refuses to run, so I don't know what I'm doing wrong.
The idea is that when you click a character (either Eris or Maru) the player switches to that character. I am trying to automate the situation so that I can change the cursor to match the character chosen, while clearing inventory. There are 3 characters, defaultplayer, eris, and maru.
The ActionPlayerSwitch and ReplaceTexture calls are taken from the scripting guide.
Any help is appreciated, thank you!
The file name is Swap.cs
using UnityEngine;
using UnityEngine.Sprites;
using AC;
public class Swap : MonoBehaviour
{
void Check ()
{
if(Eris.BooleanValue = true)
{
static ActionPlayerSwitch AC.ActionPlayerSwitch.CreateNew
( int 2,
bool takeOldPlayerPosition = false,
bool transferInventory = false
)
AC.KickStarter.cursorManager.pointerIcon.ReplaceTexture (ErisOpen);
AC.KickStarter.cursorManager.useIcon.ReplaceTexture (ErisClosed);
}
else
{
static ActionPlayerSwitch AC.ActionPlayerSwitch.CreateNew
( int 3,
bool takeOldPlayerPosition = false,
bool transferInventory = false
)
AC.KickStarter.cursorManager.pointerIcon.ReplaceTexture (MaruOpen);
AC.KickStarter.cursorManager.useIcon.ReplaceTexture (MaruClosed);
}
}
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
Your code confuses the way Actions are intended to be run through script. They need to be placed into an ActionList component, and run from there. You're also including the parameter names in your CreateNew function calls.
The included ScriptedActionListExample file demonstrates the way to do this.
Thanks Chris,
I'm afraid I don't quite understand actionlists. I checked the ScriptedActionListExample file, and one of the things the file says is to place it into my scene, however I cannot do that because I am getting the 'no monobehavior script / can't find class name' error. In fact, none of the ActionLists scripts can be used in scene, they all create an error. And the code you helped me with is in the same situation.
Is this an issue with my program, or is this expected? In which case how do you actually use these scripts if placing the components in scene doesn't work as suggested?
Thanks!
What's your full script? I only updated the relevant parts of your original code, but there are issues with it besides - no "Eris" GVar variable, and CursorManager does not have a "useIcon" variable.
This, though incomplete, should at least compile:
Bear in mind, that you don't need to approach it this way if all you're trying to do is make amendments to the Cursor textures when switching Player. You can alternatively run regular Player: Switch Actions as normal, without having to generate the ActionList through script, and then have your custom script hook into the OnSetPlayer custom event to react to it:
Thanks. I am just trying to swap cursor texture and clear inventory on character switch. Therefore, I've tried to run it as a custom event. This one does compile, and I can assign the image textures in the script. But the cursor doesn't change in game.
I am not getting any errors in my code or game, so I am a bit confused as to why this is still not working.
It occurred to me that the characters were actually player 1 and 2, since the 'narrator/starter character' is 0 not 1. So, I changed that. I also fixed the cursor texture call since I was under the false impression I needed two different calls for the texture. Besides that, I have no clue where to go.
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Sprites;
using AC;
namespace AC
{
public class Swap : MonoBehaviour
{
}
The ID of your Players will be shown next to their prefab fields in the Settings Manager.
These lines will have no effect. If you want to assign them to a cursor, you'll need to call the ReplaceTexture for the intended cursor as you are above.
The pointerIcon.ReplaceTexture lines should update the "main cursor" in the Cursor Manager - are you finding that the texture updates in the AC Game Editor?
You can place Debug.Log statements in each of the two code blocks to get confirmation in the Console that they're being run.
Thanks Chris, I fixed the call issues and that line I missed. Everything is working now.
The main issue seemed to be that the script just refused to run, or it would not rerun correctly if I selected another character after the initial selection. I tried putting it as an actual event, and listing it in action lists among other things, but the only way I go the code to work without issue is to stick an instance of the script on the camera in each scene.
A script-based custom event needs to be placed on an object in the scene for it to take effect.
To automate this, attach it to an empty, prefab it, and attach the Survive Scene Changes component. Then - in your Settings Manager's ActionList on start game asset, run the Object: Add or remove Action to spawn it in.
Ah, that makes much more sense to automate it, see I had it set on an action list originally that was set to survive scene changes, and it didn't really survive, and I tried to solve that by making an event triggered by character switching call it instead of prefabbing it. Then just gave up and put it in every scene lol.
I'll keep this in mind for the future! Thanks.