Can someone tell me what is wrong with this script?
#pragma strict
private var dead = false;
function OnControllerColliderHit(hit : ControllerColliderHit)
{
if(hit.gameObject.tag == "Respawn")
{
dead = true;
}
}
function Update ()
{
if(dead)
{
transform.position = Vector3(0,0,0);
dead = false;
}
}
}
Remove the last } from the last line or either copy and paste this one:
#pragma strict
private var dead = false;
function OnControllerColliderHit(hit : ControllerColliderHit)
{
if(hit.gameObject.tag == "Respawn")
{
dead = true;
}
}
function Update ()
{
if(dead)
{
transform.position = Vector3(0,0,0);
dead = false;
}
}
Related
I am trying to navigation application on Mapbox with Unity. I can take the location of the user but i could not able to take destination point from the user. I want to take as text. If i can able to take destination point, i can plot the route easily.
I tried the reload map, but it is not useful. Also, i tried the forward geocode user input file, but i could not make it.
namespace Mapbox.Examples
{
using Mapbox.Unity;
using UnityEngine;
using UnityEngine.UI;
using System;
using Mapbox.Geocoding;
using Mapbox.Utils;
[RequireComponent(typeof(InputField))]
public class ForwardGeocodeUserInput : MonoBehaviour
{
InputField _inputField;
ForwardGeocodeResource _resource;
Vector2d _coordinate;
public Vector2d Coordinate
{
get
{
return _coordinate;
}
}
bool _hasResponse;
public bool HasResponse
{
get
{
return _hasResponse;
}
}
public ForwardGeocodeResponse Response { get; private set; }
//public event Action<> OnGeocoderResponse = delegate { };
public event Action<ForwardGeocodeResponse> OnGeocoderResponse = delegate { };
void Awake()
{
_inputField = GetComponent<InputField>();
_inputField.onEndEdit.AddListener(HandleUserInput);
_resource = new ForwardGeocodeResource("");
}
void HandleUserInput(string searchString)
{
_hasResponse = false;
if (!string.IsNullOrEmpty(searchString))
{
_resource.Query = searchString;
MapboxAccess.Instance.Geocoder.Geocode(_resource, HandleGeocoderResponse);
}
}
void HandleGeocoderResponse(ForwardGeocodeResponse res)
{
_hasResponse = true;
if (null == res)
{
_inputField.text = "no geocode response";
}
else if (null != res.Features && res.Features.Count > 0)
{
var center = res.Features[0].Center;
//_inputField.text = string.Format("{0},{1}", center.x, center.y);
_coordinate = res.Features[0].Center;
}
Response = res;
OnGeocoderResponse(res);
}
}
}
Could you help me?
I have this tableview that is searcheable. at this point I can fill it and on search goes to a detailview. know I want to convert this to use it as an input? but how?
I have a view with the input, and I technically have a tableview that returns the value, just not in the correct manner.
tableviewmodel:
public class CMCTableViewModel : MvxViewModel
{
protected readonly ICoinMarketCapService _coinMarketCapService;
public CMCTableViewModel(ICoinMarketCapService coinMarketCapService)
{
_coinMarketCapService = coinMarketCapService;
LoadData();
}
public MvxCommand<CoinMarketCapModel> NavigateToDetailCommand
{
get
{
return new MvxCommand<CoinMarketCapModel>(
SelectedCoin =>
{
ShowViewModel<CoinViewModel>(new { coinName = SelectedCoin.Id });
}
);
}
}
private List<CoinMarketCapModel> _coinMarketCapModelList;
private CoinMarketGlobData _CoinMarketGlobDataList;
public List<CoinMarketCapModel> CoinMarketCapModelList
{
get
{
return _coinMarketCapModelList;
}
set
{
_coinMarketCapModelList = value;
RaisePropertyChanged(() => CoinMarketCapModelList);
}
}
public CoinMarketGlobData CoinMarketGlobDatas
{
get
{
return _CoinMarketGlobDataList;
}
set
{
_CoinMarketGlobDataList = value;
RaisePropertyChanged(() => CoinMarketGlobDatas);
}
}
public async void LoadData()
{
//CoinMarketCapModelList = await _coinMarketCapService.GetCoins("20");
//CoinMarketGlobDatas = await _coinMarketCapService.GetGlobalData();
CoinMarketCapModelList = await _coinMarketCapService.GetCoins();
FilteredList = CoinMarketCapModelList;
}
private List<CoinMarketCapModel> _FilteredList;
public List<CoinMarketCapModel> FilteredList
{
get
{
return _FilteredList;
}
set
{
_FilteredList = value;
RaisePropertyChanged(() => FilteredList);
}
}
public void SearchByText(string text)
{
if (string.IsNullOrWhiteSpace(text))
FilteredList = CoinMarketCapModelList;
else
{
FilteredList = CoinMarketCapModelList;
FilteredList = FilteredList.Where(m => m.Name.ToLowerInvariant().Contains(text.ToLowerInvariant())).ToList();
}
}
/// <summary>
/// Gets or sets the subtitle for the base model
/// </summary>
}
View:
[MvxFromStoryboard(StoryboardName = "Main")]
public partial class CMCTableView : MvxTableViewController<CMCTableViewModel>
{
bool useRefreshControl = false;
//private UIRefreshControl refreshControl;
private MvxUIRefreshControl refreshControl;
private void refreshTable(object sender, EventArgs e)
{
refreshControl.EndRefreshing();
TableView.ReloadData();
}
public CMCTableView (IntPtr handle) : base (handle)
{
}
UISearchBar _searchBar;
CMCTableViewSource _cmcTableViewSource;
public override void ViewDidLoad()
{
refreshControl = new MvxUIRefreshControl();
refreshControl.ValueChanged += refreshTable;
TableView.AddSubview(refreshControl);
_cmcTableViewSource = new CMCTableViewSource(this.TableView);
base.ViewDidLoad();
this.TableView.Source = _cmcTableViewSource;
this.TableView.ReloadData();
//BEGIN initialize searchbar
var searchController = new UISearchController(searchResultsController: null);
searchController.SearchBar.SizeToFit();
searchController.SearchBar.SearchBarStyle = UISearchBarStyle.Minimal;
searchController.SearchBar.Placeholder = "Select a currency";
searchController.DimsBackgroundDuringPresentation = false;
NavigationItem.HidesSearchBarWhenScrolling = false;
NavigationItem.SearchController = searchController;
_searchBar = searchController.SearchBar;
_searchBar.SearchButtonClicked += SearchBar_SearchButtonClicked;
_searchBar.TextChanged += SearchBarOnTextChanged;
_searchBar.CancelButtonClicked += SearchBarOnCancelButtonClicked;
// END initialize searchbar
MvxFluentBindingDescriptionSet<CMCTableView, CMCTableViewModel> set = new MvxFluentBindingDescriptionSet<CMCTableView, CMCTableViewModel>(this);
set.Bind(_cmcTableViewSource).To(vm => vm.FilteredList);
set.Bind(_cmcTableViewSource)
.For(src => src.SelectionChangedCommand)
.To(vm => vm.NavigateToDetailCommand);
set.Apply();
}
private void SearchBarOnCancelButtonClicked(object sender, EventArgs eventArgs)
{
((CMCTableViewModel)ViewModel).SearchByText(string.Empty);
BeginInvokeOnMainThread(() => _searchBar.ResignFirstResponder());
}
//public override void ViewWillAppear(bool animated)
//{
// base.ViewWillAppear(animated);
// NavigationController.NavigationBarHidden = false;
//}
private void SearchBarOnTextChanged(object sender, UISearchBarTextChangedEventArgs e)
{
if (string.IsNullOrWhiteSpace(_searchBar.Text))
{
((CMCTableViewModel)ViewModel).SearchByText(string.Empty);
BeginInvokeOnMainThread(() => _searchBar.ResignFirstResponder());
}
else
{
((CMCTableViewModel)ViewModel).SearchByText(_searchBar.Text);
}
}
private void SearchBar_SearchButtonClicked(object sender, EventArgs e)
{
((CMCTableViewModel)ViewModel).SearchByText(_searchBar.Text);
BeginInvokeOnMainThread(() => _searchBar.ResignFirstResponder());
}
}
i used a button as input that goes to the tableview, on selection i store the needed data(id and name in this case) in a static model. then i return to the parentview.
model:
public class addUserCoinHelperModel
{
public static string coinID { get; set; }
public static string name { get; set; }
public static string Amount { get; set; }
}
on selection in viewmodel:
public MvxCommand<CoinMarketCapModel> NavigateToDetailCommand
{
get
{
return new MvxCommand<CoinMarketCapModel>(
SelectedCoin =>
{
addUserCoinHelperModel.coinID = SelectedCoin.Id;
addUserCoinHelperModel.name = SelectedCoin.Name;
ShowViewModel<AddUserCoinViewModel>();
//ShowViewModel<CoinViewModel>(new { coinName = SelectedCoin.Id });
}
);
}
}
in the view in the viewdidload:
if (addUserCoinHelperModel.coinID != null){
btnPickCoin.SetTitle(addUserCoinHelperModel.name, UIControlState.Normal);
}
Is it possible to set a button so that it is only clickable if a bool is true?
This isn't my actual code but:
bool details_accepted = false;
public bool check_bank_details()
{
//this is simplified it's actually using an SQL query
if (bank_details = "123456789")
{
return true;
}
else
{
return false;
}
}
if (check_bank_details == true)
{
//CODE FOR SETTING BUTTON TO CLICKABLE
}
else if (check_bank_details == false)
{
//Code making Button not clickable
}
use the Enabled property
Button1.Enabled = check_bank_details();
I have created a singleton for my iOS application to access certain things globally. When I launch the application int the simulator or on my iPhone/iPad however, it sticks on the launch screen, and never reaches the appdelegates didFinishLaunchingWithOptions method (I tried to println in it). If I remove the singleton and just leave the methods and variables as global it works perfectly. Which leaves me to believe it's the singleton causing this crash. Here's the code I use. If I comment out the lines currently commented out it works perfectly like this "gameName" anywhere in my code but I know this isn't great practice so if I uncomment them and access the singleton like this "Global.sharedInstance.gameName" is when the app does not launch. I do call this singleton many times throughout the app so I'm not sure if that's the issue.
//class Global {
//
// static let sharedInstance = Global()
//
// private init() {
// println("Global Singleton created");
// }
private var optionsModel = OptionsModel()
private var gamesModel = GamesModel()
private var savesModel = SavesModel()
var device = (UIApplication.sharedApplication().delegate as! AppDelegate).device
var screenWidth = (UIApplication.sharedApplication().delegate as! AppDelegate).window!.bounds.width
var screenHeight = (UIApplication.sharedApplication().delegate as! AppDelegate).window!.bounds.height
var context = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext!
var PI = CGFloat(M_PI)
var gameIndex = 0
var player: AudioPlayer!
var gameLevel = ""
func loadSong(name: String, loops: Int) {
player = AudioPlayer(name: name, loopCount: loops)
}
func playAduio(fileName: String) {
loadSong("\(fileName)Audio", 0)
player!.play()
}
var gameName: String {
get {
return gamesModel.getName(gameIndex)
}
}
var gameDescription: String {
get {
return gamesModel.getDescription(gameIndex)
}
}
var gameIntervals: NSTimeInterval {
get {
return gamesModel.getIntervals(gameIndex)
}
}
var gameNeedsMic: Bool {
get {
return gamesModel.getMic(gameIndex)
}
}
var gameNeedsSpeech: Bool {
get {
return gamesModel.getSpeech(gameIndex)
}
}
var appLocked: Bool {
get {
return optionsModel.appLocked
}
set {
optionsModel.appLocked = newValue
}
}
var supervisorLoggedIn: Bool {
get {
return optionsModel.supervisorLoggedIn
}
set {
optionsModel.supervisorLoggedIn = newValue
}
}
var themeSongMuted: Bool {
get {
return optionsModel.themeSongMuted
}
set {
optionsModel.themeSongMuted = newValue
}
}
var gameCount: Int {
get {
return optionsModel.gameCount
}
set {
optionsModel.gameCount = newValue
}
}
var gameHighscore: Int {
get {
return savesModel.getHighscore(gameIndex)
}
set {
savesModel.setHighscore(newValue)
}
}
var gameStarCount: Int {
get {
return savesModel.getStarCount(gameIndex)
}
set {
savesModel.setStarCount(newValue)
}
}
//}
Silly me. I fixed it.
The problem was that (this is probably obvious to some of you but singletons are new to me) the singleton loaded before the app delegate loaded and some of the variables in the singleton tried to get information from the app delegate before it was created so it caused this crash. Changed it around so that i didn't load the information until after the app delegate was loaded and it works now.
Hello I'm trying to call a function to show the GameCenter LeaderBoard from an SKScene but I've been unsuccessful. Here is how I call the function from a SKScene.
class Menu: SKScene {
func score(sender:UIButton!) {
GamecenterUtils.sharedGamecenterUtils.showLeaderboardOnViewController(GamecenterUtils(),leaderboardID:"myleaderID")
}
}
I get a compiler error 'GamecenterUtils' is not convertible to UIViewController.
But I do this because GamecenterUtils is my CGGameCenterControllDelegate.
Here is the GamecenterUtils class than handles everything for Game Center:
private let _sharedGamecenterUtils = GamecenterUtils();
class GamecenterUtils : NSObject, GKGameCenterControllerDelegate {
class var sharedGamecenterUtils : GamecenterUtils{
return _sharedGamecenterUtils;
}
override init(){
}
func authenticateLocalUserOnViewController(viewController:UIViewController){
var localPlayer:GKLocalPlayer = GKLocalPlayer.localPlayer();
if (localPlayer.authenticated == false) {
localPlayer.authenticateHandler = {(authViewController, error) -> Void in
if (authViewController != nil) {
viewController.presentViewController(authViewController,animated:false,nil);
}
}
}
else {
println("Already authenticated");
}
}
func reportScore(score:Int,leaderboardID:NSString) {
var scoreReporter:GKScore = GKScore(leaderboardIdentifier:"catchthategg01");
scoreReporter.value = Int64(score);
scoreReporter.context = 0;
GKScore.reportScores([scoreReporter],{(error) -> Void in
if let reportError = error {
println("Unable to report score!\nError:\(error)");
}
else {
println("Score reported successfully!");
}
});
}
func showLeaderboardOnViewController(viewController:UIViewController?, leaderboardID:NSString){
if let containerController = viewController {
var gamecenterController:GKGameCenterViewController = GKGameCenterViewController();
gamecenterController.gameCenterDelegate = self;
gamecenterController.viewState = GKGameCenterViewControllerState.Leaderboards;
gamecenterController.leaderboardIdentifier = "catchthategg01";
viewController?.presentViewController(gamecenterController,animated:false,nil);
}
}
func gameCenterViewControllerDidFinish(_gameCenterViewController: GKGameCenterViewController!){
_gameCenterViewController.dismissViewControllerAnimated(false,nil);
}
}
Thank you for your help.