void OnTriggerEnter2D(Collider2D otherCollider) { hasTouchedNode = true; print("WE HIT OIL!"); NodeRule node = otherCollider.gameObject.GetComponent <NodeRule>(); Vector2 nodePos = node.GetComponent <BoxCollider2D>().size; Vector2 goHBp = gameObject.GetComponent <BoxCollider2D>().transform.position; if (controller.velocity.x == 1 && controller.velocity.y == 0) { moveTo = new Vector2(goHBp.x + nodePos.x, goHBp.y); } if (controller.velocity.x == -1 && controller.velocity.y == 0) { moveTo = new Vector2(goHBp.x - nodePos.x, goHBp.y); } if (controller.velocity.x == 0 && controller.velocity.y == 1) { moveTo = new Vector2(goHBp.x, goHBp.y + nodePos.y); } if (controller.velocity.x == 0 && controller.velocity.y == -1) { moveTo = new Vector2(goHBp.x, goHBp.y - nodePos.y); } // gameObject.transform.position = node.GetComponent<BoxCollider2D>().transform.position; nextMoveDirection = node.GetRandomTraversibleVector(controller.velocity); }
public void TestNodeRule() { var rule = new NodeRule(Grammar.Digit); Assert.IsTrue(rule.Match("1")); Assert.IsTrue(rule.Match("2")); Assert.IsFalse(rule.Match("x")); Assert.Throws <ArgumentNullException>(() => new NodeRule(null)); }
public int NextNode(NodeRule rule) { int dest = Random.Range(0, 3); switch (dest) { case 0: if (rule.north) { return(0); } break; case 1: if (rule.west) { return(1); } break; case 2: if (rule.east) { return(2); } break; case 3: if (rule.south) { return(3); } break; } return(rule.GetRandomTraversibleNode()); }