public DisplayMessage ( string msg, int durationMultiplier = 1 ) : void | ||
msg | string | |
durationMultiplier | int | |
return | void |
void UpdateDisplay() { display.mail = newMessage; display.DisplayMessage(); anim.SetTrigger("Visible"); StopAllCoroutines(); StartCoroutine(NotificationTimer()); }
// Update is called once per frame void Update() { timer -= Time.deltaTime; if (timer <= 0f) { if (PlayManager.Instance.signalStrength > goodStrength) { messageDisplay.DisplayMessage(PlayManager.Symbol.Good); timer = FeedbackInterval; } else if (PlayManager.Instance.signalStrength < badStrength) { messageDisplay.DisplayMessage(PlayManager.Symbol.Bad); timer = FeedbackInterval; } } }
static void Main(string[] args) { MessageDisplay m = new MessageDisplay(); m.DisplayMessage("Hello world"); dynamic d = new MessageDisplay(); d.Banana("hello world"); }
private static void BadDynamicCodeExample() { /* The class MessageDisplay contains a single method, called DisplayMessage. * The variable m is set to refer to an instance of this class, and the program calls the DisplayMessage * method on this reference. */ MessageDisplay m = new MessageDisplay(); m.DisplayMessage("Hello World"); /* The variable d is declared as dynamic and set to refer to a MessageDisplay instance. The program * then contains a call of a method called Banana on the variable d. Normally this would not compile, * because the compiler can see that this method is not present in the class. Because the variable d * has been declared as dynamic, however, the program will compile with no errors, but when the program * is executed and exception will be generated when the Banana method is called. */ dynamic d = new MessageDisplay(); d.Banana("Hello World"); }
public static void executeTest() { MessageDisplay m = new MessageDisplay(); m.DisplayMessage("Hello world"); dynamic d = new MessageDisplay(); //d.Banana("hello world"); dynamic c = 99; c = c + 1; Console.WriteLine(c); c = "hello"; c = c + " Rob"; Console.WriteLine(c); Console.ReadKey(); }
// Update is called once per frame void Update() { if (Input.GetKey(KeyCode.Escape)) { Application.Quit(); } if (remoteState == GameState.Gameover) { gameState = GameState.Gameover; } if (gameState == GameState.Gameover) { GameOver(); return; } if (remoteState == GameState.Ready && gameState == GameState.Ready) { gameState = GameState.Running; StartGame(); } if (gameState != GameState.Running) { return; } CalcSignalStrength(); if (messageUpdated) { Debug.Log("Display Message"); messageDisplay.DisplayMessage(activeMessage); messageUpdated = false; } }
public void PlayerAction() { bool animationBlock = _anim.GetBool("AnimationBlock"); float moveX = Input.GetAxis("Horizontal") * _movementSensitivity * Time.deltaTime; float moveY = Input.GetAxis("Vertical") * _movementSensitivity * Time.deltaTime; // Play sound if (moveX != 0 || moveY != 0) { if (curMovementSound == null || !curMovementSound.isPlaying) { AudioSource sound; if (_mapGeneratorScript.checkTile(_mapGeneratorScript.getGridCoordinates((Vector2)this.transform.position), 0) == MapGenerator.TileType.Water) { sound = movementWaterSounds[Random.Range(0, movementWaterSounds.Length - 1)]; } else { sound = movementSounds[Random.Range(0, movementSounds.Length - 1)]; } sound.transform.position = this.transform.position; sound.Play(); curMovementSound = sound; } } Vector2 movementVector = Vector2.zero; // ReSharper disable CompareOfFloatsByEqualityOperator if ((moveX != 0 || moveY != 0) && GameState.State.playing == GameState.TheState && !animationBlock) // ReSharper restore CompareOfFloatsByEqualityOperator { Vector2 checkPos = new Vector2(moveX, moveY) + (Vector2)transform.position; if (_mapGeneratorScript.isPassable(checkPos)) { float mod = 1.0f; if (_mapGeneratorScript.checkTile(_mapGeneratorScript.getGridCoordinates(checkPos), 0) == MapGenerator.TileType.Water) { mod = 0.5f; } transform.Translate(moveX * mod, moveY * mod, 0); _mainCamera.transform.Translate(moveX * mod, moveY * mod, 0); } _movementByMouse = false; _movementByItem = false; _moveToItem = null; _anim.SetBool("Moving", true); if (Mathf.Abs(moveX) > Mathf.Abs(moveY)) { if (moveX > 0) { PlayerAnimation("right"); } else if (moveX < 0) { PlayerAnimation("left"); } } else if (Mathf.Abs(moveY) > Mathf.Abs(moveX)) { if (moveY > 0) { PlayerAnimation("up"); } else if (moveY < 0) { PlayerAnimation("down"); } } } else { PlayerAnimation("stop"); } if (Input.GetMouseButtonDown(0) && GameState.State.playing == GameState.TheState && !animationBlock) { _movementByMouse = true; _mouseMovementTarget = _mainCamera.camera.ScreenToWorldPoint(new Vector2(Input.mousePosition.x, Input.mousePosition.y)); } if (Input.GetAxis("ItemPickup") > 0) { for (int i = 0; i < ItemParent.childCount; i++) { Transform item = ItemParent.GetChild(i); if (Vector2.Distance(item.position, transform.position) < _pickupDistance) { PlayerAnimation("pickup"); _messageDisplay.DisplayMessage("You picked something up!"); item.GetComponent <LootItem>().PickUp(); Destroy(item.gameObject); } } } if (_movementByItem && _moveToItem != null && !_movementByMouse) { movementVector = _moveToItem.transform.position - transform.position; } if (_movementByMouse) { movementVector = (_mouseMovementTarget - (Vector2)transform.position); } if (_movementByMouse || _movementByItem) { // Play sound if (curMovementSound == null || !curMovementSound.isPlaying) { AudioSource sound; if (_mapGeneratorScript.checkTile(_mapGeneratorScript.getGridCoordinates((Vector2)this.transform.position), 0) == MapGenerator.TileType.Water) { sound = movementWaterSounds[Random.Range(0, movementWaterSounds.Length - 1)]; } else { sound = movementSounds[Random.Range(0, movementSounds.Length - 1)]; } sound.transform.position = this.transform.position; sound.Play(); curMovementSound = sound; } Vector2[] compass = { Vector2.up, -Vector2.up, -Vector2.right, Vector2.right }; var maxDot = -Mathf.Infinity; var ret = Vector2.zero; foreach (Vector2 dir in compass) { var t = Vector2.Dot(movementVector, dir); if (t > maxDot) { ret = dir; maxDot = t; } } if (ret == Vector2.up) { PlayerAnimation("up"); } else if (ret == -Vector2.up) { PlayerAnimation("down"); } else if (ret == -Vector2.right) { PlayerAnimation("left"); } else if (ret == Vector2.right) { PlayerAnimation("right"); } } if (movementVector.magnitude < _mouseStopDistance) { _movementByMouse = false; if (_movementByItem && _moveToItem != null) { PlayerAnimation("pickup"); _messageDisplay.DisplayMessage("You picked something up!"); _moveToItem.GetComponent <LootItem>().PickUp(); Destroy(_moveToItem); _movementByItem = false; _moveToItem = null; } } else { if (_mapGeneratorScript.isPassable((movementVector.normalized * _movementSensitivity * Time.deltaTime) + (Vector2)transform.position) && !animationBlock) { float mod = 1.0f; if (_mapGeneratorScript.checkTile(_mapGeneratorScript.getGridCoordinates(transform.position), 0) == MapGenerator.TileType.Water) { mod = 0.5f; } transform.Translate(movementVector.normalized * _movementSensitivity * Time.deltaTime * mod); _mainCamera.transform.Translate(movementVector.normalized * _movementSensitivity * Time.deltaTime * mod); } } }
private void Update() { Vector3 uV = new Vector3(0.0f, -1.0f, 0.0f); Ray ray = new Ray(transform.position, transform.forward); if (pI.IsStrafingRight) { ray = new Ray(transform.position, Quaternion.AngleAxis( 90, transform.forward) * uV); } else if (pI.IsStrafingLeft) { ray = new Ray(transform.position, Quaternion.AngleAxis( -90, transform.forward) * uV); } else if (pI.IsWalkingBack) { ray = new Ray(transform.position, -transform.forward); } IsColliding = Physics.Raycast(ray, out currentWorldObject, pI.MoveDistance, ~0, QueryTriggerInteraction.Ignore); if (!pI.CanInput) { if (pI.Bump) { GameObject temp = currentWorldObject.transform?.gameObject; temp?.GetComponent <BreakingWall>()?.Break(); } return; } if (IsColliding) { // Definetly change this to do it one time. ObjectTouched = currentWorldObject.transform.gameObject; // This could be better if ((ObjectTouched.layer == 8) || (ObjectTouched.layer == 9)) { objectHolder = ObjectTouched.GetComponent <DataHolder>(); objectData = objectHolder?.GetData(inventory.equipedItem); mD.DisplayMessage(objectData); } } else { IsColliding = false; objectData = null; ObjectTouched = null; mD.CleanMessage(); } if ((ObjectTouched != null) && !pI.IsStrafingLeft && !pI.IsStrafingRight) { if (!pI.IsWalking && pI.IsInteracting && IsColliding) { if (objectData == null) { return; } switch (objectData.InteractionType) { case InteractionType.isGrabable: inventory.AddItem(objectData as ItemData); objectHolder.DestroyObject(); mD.CleanMessage(); objectData = null; break; case InteractionType.isUsable: interactor = ObjectTouched.GetComponent <ManualInteractor>(); InteractionResult itemused = interactor.Toggle( inventory?.equipedItem, transform.position); switch (itemused) { case InteractionResult.WrongIntMessage: StartDialogue(wrongInteaction); break; case InteractionResult.UseItem: inventory.ClearEquiped(); break; } break; case InteractionType.isExit: interactor = ObjectTouched.GetComponent <ManualInteractor>(); interactor.Toggle( inventory?.equipedItem, transform.position); break; case InteractionType.isNPC: StartDialogue((objectData as NpcData).Dialogue); break; default: print("Porque é que essa coisa é trigger ?"); break; } } pI.IsInteracting = false; } }